kicad: add rotation method to circles and polygons

This commit is contained in:
jaseg 2024-07-19 19:28:15 +02:00
parent fd63c44314
commit 091ee84910

View file

@ -182,6 +182,10 @@ class Circle(BBoxMixin, WidthMixin):
self.center = self.center.with_offset(x, y)
self.end = self.end.with_offset(x, y)
def rotate(self, angle, cx=0, cy=0):
self.center = self.center.with_rotation(angle, cx, cy)
self.end = self.end.with_rotation(angle, cx, cy)
@sexp_type('gr_arc')
class Arc(WidthMixin, BBoxMixin):
@ -205,11 +209,6 @@ class Arc(WidthMixin, BBoxMixin):
self.mid = center_arc_to_kicad_mid(XYCoord(self.center), self.start, self.end)
self.center = None
def rotate(self, angle, cx=None, cy=None):
self.start.x, self.start.y = rotate_point(self.start.x, self.start.y, angle, cx, cy)
self.mid.x, self.mid.y = rotate_point(self.mid.x, self.mid.y, angle, cx, cy)
self.end.x, self.end.y = rotate_point(self.end.x, self.end.y, angle, cx, cy)
def render(self, variables=None):
if not (w := self.stroke.width if self.stroke else self.width):
return
@ -225,6 +224,11 @@ class Arc(WidthMixin, BBoxMixin):
self.mid = self.mid.with_offset(x, y)
self.end = self.end.with_offset(x, y)
def rotate(self, angle, cx=None, cy=None):
self.start.x, self.start.y = rotate_point(self.start.x, self.start.y, angle, cx, cy)
self.mid.x, self.mid.y = rotate_point(self.mid.x, self.mid.y, angle, cx, cy)
self.end.x, self.end.y = rotate_point(self.end.x, self.end.y, angle, cx, cy)
@sexp_type('gr_poly')
class Polygon(BBoxMixin, WidthMixin):
@ -266,6 +270,9 @@ class Polygon(BBoxMixin, WidthMixin):
def offset(self, x=0, y=0):
self.pts = [pt.with_offset(x, y) for pt in self.pts]
def rotate(self, angle, cx=0, cy=0):
self.pts = [pt.with_rotation(angle, cx, cy) for pt in self.pts]
@sexp_type('gr_curve')
class Curve(BBoxMixin, WidthMixin):