diff options
Diffstat (limited to 'gerbonara/aperture_macros')
-rw-r--r-- | gerbonara/aperture_macros/parse.py | 2 | ||||
-rw-r--r-- | gerbonara/aperture_macros/primitive.py | 12 |
2 files changed, 10 insertions, 4 deletions
diff --git a/gerbonara/aperture_macros/parse.py b/gerbonara/aperture_macros/parse.py index c1a776f..57de857 100644 --- a/gerbonara/aperture_macros/parse.py +++ b/gerbonara/aperture_macros/parse.py @@ -13,6 +13,7 @@ from . import primitive as ap from .expression import * from ..utils import MM +# we make our own here instead of using math.degrees to make sure this works with expressions, too. def rad_to_deg(x): return (x / math.pi) * 180 @@ -190,6 +191,7 @@ class GenericMacros: *_generic_hole(4)]) # w must be larger than h + # params: width, height, *hole, rotation obround = ApertureMacro('GNO', [ ap.CenterLine('mm', [1, var(1), var(2), 0, 0, var(5) * -deg_per_rad]), ap.Circle('mm', [1, var(2), +var(1)/2, 0, var(5) * -deg_per_rad]), diff --git a/gerbonara/aperture_macros/primitive.py b/gerbonara/aperture_macros/primitive.py index 4a991f1..8d4bf4f 100644 --- a/gerbonara/aperture_macros/primitive.py +++ b/gerbonara/aperture_macros/primitive.py @@ -12,6 +12,7 @@ from .expression import Expression, UnitExpression, ConstantExpression, expr from .. import graphic_primitives as gp from .. import graphic_objects as go +from ..utils import rotate_point def point_distance(a, b): @@ -20,9 +21,11 @@ def point_distance(a, b): return math.sqrt((x2 - x1)**2 + (y2 - y1)**2) +# we make our own here instead of using math.degrees to make sure this works with expressions, too. def deg_to_rad(a): return a * (math.pi / 180) + def rad_to_deg(a): return a * (180 / math.pi) @@ -92,7 +95,7 @@ class Circle(Primitive): def to_graphic_primitives(self, offset, rotation, variable_binding={}, unit=None, polarity_dark=True): with self.Calculator(self, variable_binding, unit) as calc: - x, y = gp.rotate_point(calc.x, calc.y, deg_to_rad(calc.rotation) + rotation, 0, 0) + x, y = rotate_point(calc.x, calc.y, deg_to_rad(calc.rotation) + rotation, 0, 0) x, y = x+offset[0], y+offset[1] return [ gp.Circle(x, y, calc.diameter/2, polarity_dark=(bool(calc.exposure) == polarity_dark)) ] @@ -123,6 +126,7 @@ class VectorLine(Primitive): delta_y = calc.end_y - calc.start_y length = point_distance((calc.start_x, calc.start_y), (calc.end_x, calc.end_y)) + center_x, center_y = rotate_point(center_x, center_y, deg_to_rad(calc.rotation) + rotation, 0, 0) center_x, center_y = center_x+offset[0], center_y+offset[1] rotation += deg_to_rad(calc.rotation) + math.atan2(delta_y, delta_x) @@ -181,7 +185,7 @@ class Polygon(Primitive): def to_graphic_primitives(self, offset, rotation, variable_binding={}, unit=None, polarity_dark=True): with self.Calculator(self, variable_binding, unit) as calc: rotation += deg_to_rad(calc.rotation) - x, y = gp.rotate_point(calc.x, calc.y, rotation, 0, 0) + x, y = rotate_point(calc.x, calc.y, rotation, 0, 0) x, y = x+offset[0], y+offset[1] return [ gp.ArcPoly.from_regular_polygon(calc.x, calc.y, calc.diameter/2, calc.n_vertices, rotation, polarity_dark=(bool(calc.exposure) == polarity_dark)) ] @@ -209,7 +213,7 @@ class Thermal(Primitive): def to_graphic_primitives(self, offset, rotation, variable_binding={}, unit=None, polarity_dark=True): with self.Calculator(self, variable_binding, unit) as calc: rotation += deg_to_rad(calc.rotation) - x, y = gp.rotate_point(calc.x, calc.y, rotation, 0, 0) + x, y = rotate_point(calc.x, calc.y, rotation, 0, 0) x, y = x+offset[0], y+offset[1] dark = (bool(calc.exposure) == polarity_dark) @@ -271,7 +275,7 @@ class Outline(Primitive): def to_graphic_primitives(self, offset, rotation, variable_binding={}, unit=None, polarity_dark=True): with self.Calculator(self, variable_binding, unit) as calc: rotation += deg_to_rad(calc.rotation) - bound_coords = [ gp.rotate_point(calc(x), calc(y), rotation, 0, 0) for x, y in self.coords ] + bound_coords = [ rotate_point(calc(x), calc(y), rotation, 0, 0) for x, y in self.coords ] bound_coords = [ (x+offset[0], y+offset[1]) for x, y in bound_coords ] bound_radii = [None] * len(bound_coords) return [gp.ArcPoly(bound_coords, bound_radii, polarity_dark=(bool(calc.exposure) == polarity_dark))] |