diff options
author | opiopan <opiopan@gmail.com> | 2019-04-03 00:30:00 +0900 |
---|---|---|
committer | opiopan <opiopan@gmail.com> | 2019-04-03 00:30:00 +0900 |
commit | cb420e39e278f7ab6f002600a7698d7be101eb7d (patch) | |
tree | 1d82fcd72627c71715ec0b9724c8f976a49bdfdd /gerberex | |
parent | b72d891998cc87273b9dd8bfe4d864cbe6a8cc62 (diff) | |
download | pcb-tools-extension-cb420e39e278f7ab6f002600a7698d7be101eb7d.tar.gz pcb-tools-extension-cb420e39e278f7ab6f002600a7698d7be101eb7d.tar.bz2 pcb-tools-extension-cb420e39e278f7ab6f002600a7698d7be101eb7d.zip |
fix a rotaion issue
Diffstat (limited to 'gerberex')
-rw-r--r-- | gerberex/dxf.py | 8 | ||||
-rw-r--r-- | gerberex/dxf_path.py | 4 | ||||
-rw-r--r-- | gerberex/rs274x.py | 16 | ||||
-rw-r--r-- | gerberex/utility.py | 8 |
4 files changed, 25 insertions, 11 deletions
diff --git a/gerberex/dxf.py b/gerberex/dxf.py index 1b2ddf7..39d256b 100644 --- a/gerberex/dxf.py +++ b/gerberex/dxf.py @@ -11,17 +11,11 @@ from gerber.utils import inch, metric, write_gerber_value from gerber.gerber_statements import ADParamStmt from gerber.excellon_statements import ExcellonTool from gerber.excellon_statements import CoordinateStmt +from gerberex.utility import is_equal_point, is_equal_value from gerberex.dxf_path import generate_closed_paths ACCEPTABLE_ERROR = 0.001 -def is_equal_value(a, b, error_range=0): - return a - b <= error_range and a - b >= -error_range - -def is_equal_point(a, b, error_range=0): - return is_equal_value(a[0], b[0], error_range) and \ - is_equal_value(a[1], b[1], error_range) - class DxfStatement(object): def __init__(self, entity): self.entity = entity diff --git a/gerberex/dxf_path.py b/gerberex/dxf_path.py index 930d8d2..2825c58 100644 --- a/gerberex/dxf_path.py +++ b/gerberex/dxf_path.py @@ -5,6 +5,7 @@ from gerber.utils import inch, metric, write_gerber_value from gerber.cam import FileSettings +from gerberex.utility import is_equal_point, is_equal_value class DxfPath(object): def __init__(self, statement, error_range=0): @@ -21,12 +22,10 @@ class DxfPath(object): @property def is_closed(self): - from gerberex.dxf import is_equal_point return len(self.statements) > 1 and \ is_equal_point(self.start, self.end, self.error_range) def is_equal_to(self, target, error_range=0): - from gerberex.dxf import is_equal_point if not isinstance(target, DxfPath): return False if len(self.statements) != len(target.statements): @@ -59,7 +58,6 @@ class DxfPath(object): self.statements = rlist def merge(self, element, error_range=0): - from gerberex.dxf import is_equal_point if self.is_closed or element.is_closed: return False if not error_range: diff --git a/gerberex/rs274x.py b/gerberex/rs274x.py index 4b477d3..4eb317d 100644 --- a/gerberex/rs274x.py +++ b/gerberex/rs274x.py @@ -30,11 +30,25 @@ class GerberFile(gerber.rs274x.GerberFile): if angle % 360 == 0: return self._generalize_aperture() + last_x = 0 + last_y = 0 + last_rx = 0 + last_ry = 0 for statement in self.statements: if isinstance(statement, AMParamStmtEx): statement.rotate(angle, center) elif isinstance(statement, CoordStmt) and statement.x != None and statement.y != None: - statement.x, statement.y = rotate(statement.x, statement.y, angle, center) + if statement.i != None and statement.j != None: + cx = last_x + statement.i + cy = last_y + statement.j + cx, cy = rotate(cx, cy, angle, center) + statement.i = cx - last_rx + statement.j = cy - last_ry + last_x = statement.x + last_y = statement.y + last_rx, last_ry = rotate(statement.x, statement.y, angle, center) + statement.x = last_rx + statement.y = last_ry def _generalize_aperture(self): RECTANGLE = 0 diff --git a/gerberex/utility.py b/gerberex/utility.py index 852519a..f90df96 100644 --- a/gerberex/utility.py +++ b/gerberex/utility.py @@ -11,3 +11,11 @@ def rotate(x, y, angle, center): angle = angle * pi / 180.0 return (cos(angle) * x0 - sin(angle) * y0 + center[0], sin(angle) * x0 + cos(angle) * y0 + center[1]) + +def is_equal_value(a, b, error_range=0): + return a - b <= error_range and a - b >= -error_range + + +def is_equal_point(a, b, error_range=0): + return is_equal_value(a[0], b[0], error_range) and \ + is_equal_value(a[1], b[1], error_range) |