diff --git a/src/gerbonara/aperture_macros/primitive.py b/src/gerbonara/aperture_macros/primitive.py index da10cc9..d31aef8 100644 --- a/src/gerbonara/aperture_macros/primitive.py +++ b/src/gerbonara/aperture_macros/primitive.py @@ -105,6 +105,10 @@ class Circle(Primitive): with self.Calculator(self, variable_binding, unit) as calc: x, y = rotate_point(calc.x, calc.y, -(deg_to_rad(calc.rotation) + rotation), 0, 0) x, y = x+offset[0], y+offset[1] + + if math.isclose(calc.diameter, 0): + return [] + return [ gp.Circle(x, y, calc.diameter/2, polarity_dark=(bool(calc.exposure) == polarity_dark)) ] def substitute_params(self, binding, unit): @@ -144,6 +148,9 @@ class VectorLine(Primitive): center_x, center_y = center_x+offset[0], center_y+offset[1] rotation += deg_to_rad(calc.rotation) + math.atan2(delta_y, delta_x) + if math.isclose(calc.width, 0): + return [] + return [ gp.Rectangle(center_x, center_y, length, calc.width, rotation=rotation, polarity_dark=(bool(calc.exposure) == polarity_dark)) ] @@ -182,6 +189,9 @@ class CenterLine(Primitive): x, y = x+offset[0], y+offset[1] w, h = calc.width, calc.height + if math.isclose(calc.width, 0) or math.isclose(calc.height, 0): + return [] + return [ gp.Rectangle(x, y, w, h, rotation, polarity_dark=(bool(calc.exposure) == polarity_dark)) ] def substitute_params(self, binding, unit): @@ -217,7 +227,8 @@ class Polygon(Primitive): rotation += deg_to_rad(calc.rotation) 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, + print('xy', calc.x, calc.y) + return [ gp.ArcPoly.from_regular_polygon(x, y, calc.diameter/2, int(calc.n_vertices), rotation, polarity_dark=(bool(calc.exposure) == polarity_dark)) ] def dilated(self, offset, unit): @@ -251,6 +262,9 @@ class Moire(Primitive): x, y = rotate_point(calc.x, calc.y, -rotation, 0, 0) x, y = x+offset[0], y+offset[1] + if math.isclose(calc.d_outer, 0): + return [] + pitch = calc.line_thickness + calc.gap_w for i in range(int(round(calc.num_circles))): yield gp.Circle(x, y, calc.d_outer/2 - i*pitch, polarity_dark=True) @@ -297,6 +311,9 @@ class Thermal(Primitive): dark = True + if math.isclose(calc.d_outer, 0): + return [] + return [ gp.Circle(x, y, calc.d_outer/2, polarity_dark=dark), gp.Circle(x, y, calc.d_inner/2, polarity_dark=not dark), @@ -383,6 +400,10 @@ class Outline(Primitive): bound_coords = [ rotate_point(calc(x), calc(y), -rotation, 0, 0) for x, y in self.points ] bound_coords = [ (x+offset[0], y+offset[1]) for x, y in bound_coords ] bound_radii = [None] * len(bound_coords) + + if len(bound_coords) < 3: + return [] + return [gp.ArcPoly(bound_coords, bound_radii, polarity_dark=(bool(calc.exposure) == polarity_dark))] def dilated(self, offset, unit): diff --git a/src/gerbonara/apertures.py b/src/gerbonara/apertures.py index 1f867c3..fae129e 100644 --- a/src/gerbonara/apertures.py +++ b/src/gerbonara/apertures.py @@ -266,7 +266,7 @@ class RectangleAperture(Aperture): return GenericMacros.rect(MM(self.w, self.unit), MM(self.h, self.unit), MM(self.hole_dia, self.unit), - self.rotation) + rotation) def _params(self, unit=None): return _strip_right( diff --git a/tests/test_aperture_macro.py b/tests/test_aperture_macro.py index 822ea79..b7b0d97 100644 --- a/tests/test_aperture_macro.py +++ b/tests/test_aperture_macro.py @@ -35,7 +35,7 @@ from .utils import * @contextmanager -def run_aperture_macro_test(tmpfile, img_support, inst: ApertureMacroInstance, epsilon=1e-4): +def run_aperture_macro_test(tmpfile, img_support, inst: ApertureMacroInstance, epsilon=1e-3): gbr = GerberFile() inst_rot_90 = inst.rotated(math.pi/2) @@ -66,7 +66,8 @@ def run_aperture_macro_test(tmpfile, img_support, inst: ApertureMacroInstance, e # resvg. We have to do this since gerbv's built-in cairo-based PNG export has severe aliasing issues. In contrast, # using resvg for both allows an apples-to-apples comparison of both results. ref_svg = tmpfile('Reference export', '.svg') - img_support.gerbv_export(out_gbr, ref_svg, origin=bounds[0], size=bounds[1], fg='#000000', bg='#ffffff') + w, h = bounds[1][0] - bounds[0][0], bounds[1][1] - bounds[0][1] + img_support.gerbv_export(out_gbr, ref_svg, origin=bounds[0], size=(w, h), fg='#000000', bg='#ffffff') with svg_soup(ref_svg) as soup: img_support.cleanup_gerbv_svg(soup)