diff options
author | jaseg <git@jaseg.de> | 2022-01-17 23:14:52 +0100 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2022-01-17 23:14:52 +0100 |
commit | 73a44901c0ef0e94e9465c2f35750ca6f85a4473 (patch) | |
tree | a5c66526a38fe5a4e3d004dc7127680b6d0e25c6 /gerbonara/gerber/graphic_objects.py | |
parent | 336a18fb493c79824323a59865083a0037a4a2f4 (diff) | |
download | gerbonara-73a44901c0ef0e94e9465c2f35750ca6f85a4473.tar.gz gerbonara-73a44901c0ef0e94e9465c2f35750ca6f85a4473.tar.bz2 gerbonara-73a44901c0ef0e94e9465c2f35750ca6f85a4473.zip |
Excellon, unit conversion WIP
Diffstat (limited to 'gerbonara/gerber/graphic_objects.py')
-rw-r--r-- | gerbonara/gerber/graphic_objects.py | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/gerbonara/gerber/graphic_objects.py b/gerbonara/gerber/graphic_objects.py index 8f2e4b4..e251540 100644 --- a/gerbonara/gerber/graphic_objects.py +++ b/gerbonara/gerber/graphic_objects.py @@ -10,7 +10,7 @@ from .gerber_statements import * def convert(value, src, dst): if src == dst or src is None or dst is None or value is None: return value - elif dst == 'mm': + elif dst == MM: return value * 25.4 else: return value / 25.4 @@ -27,20 +27,15 @@ class GerberObject: def converted(self, unit): return replace(self, - **{ - f.name: convert(getattr(self, f.name), self.unit, unit) - for f in fields(self) if type(f.type) is Length - }) + **{ f.name: self.unit.to(unit, getattr(self, f.name)) + for f in fields(self) if type(f.type) is Length }) - def _conv(self, value, unit): - return convert(value, src=unit, dst=self.unit) - - def with_offset(self, dx, dy, unit='mm'): - dx, dy = self._conv(dx, unit), self._conv(dy, unit) + def with_offset(self, dx, dy, unit=MM): + dx, dy = self.unit.from(unit, dx), self.unit.from(unit, dy) return self._with_offset(dx, dy) - def rotate(self, rotation, cx=0, cy=0, unit='mm'): - cx, cy = self._conv(cx, unit), self._conv(cy, unit) + def rotate(self, rotation, cx=0, cy=0, unit=MM): + cx, cy = self.unit.from(unit, cx), self.unit.from(unit, cy) self._rotate(rotation, cx, cy) def bounding_box(self, unit=None): @@ -138,9 +133,10 @@ class Region(GerberObject): if unit == self.unit: yield self.poly else: - conv_outline = [ (convert(x, self.unit, unit), convert(y, self.unit, unit)) + to = lambda value: self.unit.to(unit, value) + conv_outline = [ (to(x), to(y)) for x, y in self.poly.outline ] - convert_entry = lambda entry: (entry[0], (convert(entry[1][0], self.unit, unit), convert(entry[1][1], self.unit, unit))) + convert_entry = lambda entry: (entry[0], (to(entry[1][0]), to(entry[1][1]))) conv_arc = [ None if entry is None else convert_entry(entry) for entry in self.poly.arc_centers ] yield gp.ArcPoly(conv_outline, conv_arc) |