diff options
author | jaseg <git@jaseg.de> | 2024-11-08 11:41:11 +0100 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2024-11-08 11:41:11 +0100 |
commit | 8ffa7c1b76b9dc9238410c6221cb0d00ba49d4ae (patch) | |
tree | 6abf821f324abbde62cfccfe09731542e2def3ce /gerbonara/rs274x.py | |
parent | be8371c7bc21abe12db49f9dd38dac4513a64886 (diff) | |
download | gerbonara-8ffa7c1b76b9dc9238410c6221cb0d00ba49d4ae.tar.gz gerbonara-8ffa7c1b76b9dc9238410c6221cb0d00ba49d4ae.tar.bz2 gerbonara-8ffa7c1b76b9dc9238410c6221cb0d00ba49d4ae.zip |
Fix svg orientation and improve OrCAD rendering
Diffstat (limited to 'gerbonara/rs274x.py')
-rw-r--r-- | gerbonara/rs274x.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/gerbonara/rs274x.py b/gerbonara/rs274x.py index 108ccd6..6d22fbd 100644 --- a/gerbonara/rs274x.py +++ b/gerbonara/rs274x.py @@ -28,7 +28,7 @@ import dataclasses import functools from .cam import CamFile, FileSettings -from .utils import MM, Inch, units, InterpMode, UnknownStatementWarning +from .utils import MM, Inch, units, InterpMode, UnknownStatementWarning, convex_hull from .aperture_macros.parse import ApertureMacro, GenericMacros from . import graphic_primitives as gp from . import graphic_objects as go @@ -376,7 +376,25 @@ class GerberFile(CamFile): """ Invert the polarity (color) of each object in this file. """ for obj in self.objects: obj.polarity_dark = not p.polarity_dark - + + def convex_hull(self, tol=0.01, unit=None): + unit = unit or self.unit + points = [] + + for obj in self.objects: + if isinstance(obj, go.Line): + line = obj.as_primitive(unit) + points.append((line.x1, line.y1)) + points.append((line.x2, line.y2)) + + elif isinstance(obj, go.Arc): + for obj in obj.approximate(tol, unit): + line = obj.as_primitive(unit) + points.append((line.x1, line.y1)) + points.append((line.x2, line.y2)) + + return convex_hull(points) + class GraphicsState: """ Internal class used to track Gerber processing state during import and export. |