From d8ff4a468b7299a370905b5c12c62393e369c61a Mon Sep 17 00:00:00 2001 From: jaseg Date: Wed, 29 Dec 2021 22:03:33 +0100 Subject: Fix some failing tests --- gerbonara/gerber/graphic_objects.py | 49 ++++++++++++++----------------------- 1 file changed, 19 insertions(+), 30 deletions(-) (limited to 'gerbonara/gerber/graphic_objects.py') diff --git a/gerbonara/gerber/graphic_objects.py b/gerbonara/gerber/graphic_objects.py index 47ed718..9902dee 100644 --- a/gerbonara/gerber/graphic_objects.py +++ b/gerbonara/gerber/graphic_objects.py @@ -1,5 +1,6 @@ -from dataclasses import dataclass, KW_ONLY +import math +from dataclasses import dataclass, KW_ONLY, astuple from . import graphic_primitives as gp from .gerber_statements import * @@ -160,57 +161,45 @@ class Slot(GerberObject): yield gp.Line(*self.p1, *self.p2, self.width, polarity_dark=self.polarity_dark) +@dataclass class Arc(GerberObject): - x : float - y : float - r : float - angle1 : float # radians! - angle2 : float # radians! + x1 : float + y1 : float + x2 : float + y2 : float + cx : float + cy : float + flipped : bool aperture : object - @classmethod - def from_coords(kls, start, end, center_delta, aperture, flipped=False, polarity_dark=True): - x0, y0 = start - x1, y1 = end - dx, dy = center_delta - cx, cy = x0+dx, y0+dy - angle1 = math.atan2(y0-cy, x0-cx) - angle2 = math.atan2(y1-cy, x1-cx) - aperture = self.aperture - if flipped: - angle1, angle2 = angle2, angle1 - r = math.sqrt(dx**2 + dy**2) - # r should be approximately (depending on coordinate resolution) equal for center->start and center->end - return kls(cx, cy, r, angle1, angle2, polarity_dark=polarity_dark) - def with_offset(self, dx, dy): return replace(self, x=self.x+dx, y=self.y+dy) @property def p1(self): - return self.x + self.r*sin(self.angle1), self.y + self.r*cos(self.angle1) + return self.x1, self.y1 @property def p2(self): - return self.x + self.r*sin(self.angle2), self.y + self.r*cos(self.angle2) + return self.x2, self.y2 @property def center(self): - return (self.x, self.y) + return self.x1 + self.cx, self.y1 + self.cy def rotate(self, rotation, cx=None, cy=None): - self.x, self.y = gp.rotate_point(self.x, self.y, rotation, cx, cy) - self.angle1 = (self.angle1+rotation) % (2*math.pi) - self.angle2 = (self.angle2+rotation) % (2*math.pi) + cx, cy = gp.rotate_point(*self.center, rotation, cx, cy) + self.x1, self.y1 = gp.rotate_point(self.x1, self.y1, rotation, cx, cy) + self.x2, self.y2 = gp.rotate_point(self.x2, self.y2, rotation, cx, cy) + self.cx, self.cy = cx - self.x1, cy - self.y1 def to_primitives(self): - yield gp.Arc(self.x, self.y, self.r, self.angle1, self.angle2, self.aperture.equivalent_width, polarity_dark=self.polarity_dark) + yield gp.Arc(*astuple(self)[:7], width=self.aperture.equivalent_width, polarity_dark=self.polarity_dark) def to_statements(self, gs): yield from gs.set_aperture(self.aperture) yield from gs.set_interpolation_mode(CircularCCWModeStmt) yield from gs.set_current_point(self.p1) - x2, y2 = self.p2 - yield InterpolateStmt(x2, y2, self.x-x2, self.y-y2) + yield InterpolateStmt(self.x2, self.y2, self.cx, self.cy) -- cgit