From f5abd5b0bdc0b9f524456dc9216bd0f3732e82a0 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Tue, 28 Oct 2014 22:11:43 -0400 Subject: Add arc rendering and tests --- gerber/tests/test_primitives.py | 85 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 gerber/tests/test_primitives.py (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py new file mode 100644 index 0000000..29036b4 --- /dev/null +++ b/gerber/tests/test_primitives.py @@ -0,0 +1,85 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# Author: Hamilton Kibbe +from ..primitives import * +from tests import * + + + +def test_line_angle(): + """ Test Line primitive angle calculation + """ + cases = [((0, 0), (1, 0), math.radians(0)), + ((0, 0), (1, 1), math.radians(45)), + ((0, 0), (0, 1), math.radians(90)), + ((0, 0), (-1, 1), math.radians(135)), + ((0, 0), (-1, 0), math.radians(180)), + ((0, 0), (-1, -1), math.radians(225)), + ((0, 0), (0, -1), math.radians(270)), + ((0, 0), (1, -1), math.radians(315)),] + for start, end, expected in cases: + l = Line(start, end, 0) + line_angle = (l.angle + 2 * math.pi) % (2 * math.pi) + assert_almost_equal(line_angle, expected) + +def test_line_bounds(): + """ Test Line primitive bounding box calculation + """ + cases = [((0, 0), (1, 1), ((0, 1), (0, 1))), + ((-1, -1), (1, 1), ((-1, 1), (-1, 1))), + ((1, 1), (-1, -1), ((-1, 1), (-1, 1))), + ((-1, 1), (1, -1), ((-1, 1), (-1, 1))),] + for start, end, expected in cases: + l = Line(start, end, 0) + assert_equal(l.bounding_box, expected) + +def test_arc_radius(): + """ Test Arc primitive radius calculation + """ + cases = [((-3, 4), (5, 0), (0, 0), 5), + ((0, 1), (1, 0), (0, 0), 1),] + + for start, end, center, radius in cases: + a = Arc(start, end, center, 'clockwise', 0) + assert_equal(a.radius, radius) + + +def test_arc_sweep_angle(): + """ Test Arc primitive sweep angle calculation + """ + cases = [((1, 0), (0, 1), (0, 0), 'counterclockwise', math.radians(90)), + ((1, 0), (0, 1), (0, 0), 'clockwise', math.radians(270)), + ((1, 0), (-1, 0), (0, 0), 'clockwise', math.radians(180)), + ((1, 0), (-1, 0), (0, 0), 'counterclockwise', math.radians(180)),] + + for start, end, center, direction, sweep in cases: + a = Arc(start, end, center, direction, 0) + assert_equal(a.sweep_angle, sweep) + + +def test_arc_bounds(): + """ Test Arc primitive bounding box calculation + """ + cases = [((1, 0), (0, 1), (0, 0), 'clockwise', ((-1, 1), (-1, 1))), + ((1, 0), (0, 1), (0, 0), 'counterclockwise', ((0, 1), (0, 1))), + #TODO: ADD MORE TEST CASES HERE + ] + + for start, end, center, direction, bounds in cases: + a = Arc(start, end, center, direction, 0) + assert_equal(a.bounding_box, bounds) + +def test_circle_radius(): + """ Test Circle primitive radius calculation + """ + c = Circle((1, 1), 2) + assert_equal(c.radius, 1) + +def test_circle_bounds(): + """ Test Circle bounding box calculation + """ + c = Circle((1, 1), 2) + assert_equal(c.bounding_box, ((0, 2), (0, 2))) + + -- cgit From 360eddc3c421cc193716b17d33cc94d8444d64ce Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 1 Feb 2015 13:40:08 -0500 Subject: Added primitives and tests --- gerber/tests/test_primitives.py | 134 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 5 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index 29036b4..4534484 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -6,7 +6,6 @@ from ..primitives import * from tests import * - def test_line_angle(): """ Test Line primitive angle calculation """ @@ -22,7 +21,8 @@ def test_line_angle(): l = Line(start, end, 0) line_angle = (l.angle + 2 * math.pi) % (2 * math.pi) assert_almost_equal(line_angle, expected) - + + def test_line_bounds(): """ Test Line primitive bounding box calculation """ @@ -34,6 +34,7 @@ def test_line_bounds(): l = Line(start, end, 0) assert_equal(l.bounding_box, expected) + def test_arc_radius(): """ Test Arc primitive radius calculation """ @@ -65,21 +66,144 @@ def test_arc_bounds(): ((1, 0), (0, 1), (0, 0), 'counterclockwise', ((0, 1), (0, 1))), #TODO: ADD MORE TEST CASES HERE ] - for start, end, center, direction, bounds in cases: a = Arc(start, end, center, direction, 0) assert_equal(a.bounding_box, bounds) - + + def test_circle_radius(): """ Test Circle primitive radius calculation """ c = Circle((1, 1), 2) assert_equal(c.radius, 1) - + + def test_circle_bounds(): """ Test Circle bounding box calculation """ c = Circle((1, 1), 2) assert_equal(c.bounding_box, ((0, 2), (0, 2))) + + +def test_ellipse_ctor(): + """ Test ellipse creation + """ + e = Ellipse((2, 2), 3, 2) + assert_equal(e.position, (2, 2)) + assert_equal(e.width, 3) + assert_equal(e.height, 2) + + +def test_ellipse_bounds(): + """ Test ellipse bounding box calculation + """ + e = Ellipse((2, 2), 4, 2) + assert_equal(e.bounding_box, ((0, 4), (1, 3))) + e = Ellipse((2, 2), 4, 2, rotation=90) + assert_equal(e.bounding_box, ((1, 3), (0, 4))) + e = Ellipse((2, 2), 4, 2, rotation=180) + assert_equal(e.bounding_box, ((0, 4), (1, 3))) + e = Ellipse((2, 2), 4, 2, rotation=270) + assert_equal(e.bounding_box, ((1, 3), (0, 4))) + +def test_rectangle_ctor(): + """ Test rectangle creation + """ + test_cases = (((0,0), 1, 1), ((0, 0), 1, 2), ((1,1), 1, 2)) + for pos, width, height in test_cases: + r = Rectangle(pos, width, height) + assert_equal(r.position, pos) + assert_equal(r.width, width) + assert_equal(r.height, height) + +def test_rectangle_bounds(): + """ Test rectangle bounding box calculation + """ + r = Rectangle((0,0), 2, 2) + xbounds, ybounds = r.bounding_box + assert_array_almost_equal(xbounds, (-1, 1)) + assert_array_almost_equal(ybounds, (-1, 1)) + r = Rectangle((0,0), 2, 2, rotation=45) + xbounds, ybounds = r.bounding_box + assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) + assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + +def test_diamond_ctor(): + """ Test diamond creation + """ + test_cases = (((0,0), 1, 1), ((0, 0), 1, 2), ((1,1), 1, 2)) + for pos, width, height in test_cases: + d = Diamond(pos, width, height) + assert_equal(d.position, pos) + assert_equal(d.width, width) + assert_equal(d.height, height) + +def test_diamond_bounds(): + """ Test diamond bounding box calculation + """ + d = Diamond((0,0), 2, 2) + xbounds, ybounds = d.bounding_box + assert_array_almost_equal(xbounds, (-1, 1)) + assert_array_almost_equal(ybounds, (-1, 1)) + d = Diamond((0,0), math.sqrt(2), math.sqrt(2), rotation=45) + xbounds, ybounds = d.bounding_box + assert_array_almost_equal(xbounds, (-1, 1)) + assert_array_almost_equal(ybounds, (-1, 1)) + + +def test_chamfer_rectangle_ctor(): + """ Test chamfer rectangle creation + """ + test_cases = (((0,0), 1, 1, 0.2, (True, True, False, False)), + ((0, 0), 1, 2, 0.3, (True, True, True, True)), + ((1,1), 1, 2, 0.4, (False, False, False, False))) + for pos, width, height, chamfer, corners in test_cases: + r = ChamferRectangle(pos, width, height, chamfer, corners) + assert_equal(r.position, pos) + assert_equal(r.width, width) + assert_equal(r.height, height) + assert_equal(r.chamfer, chamfer) + assert_array_almost_equal(r.corners, corners) + +def test_chamfer_rectangle_bounds(): + """ Test chamfer rectangle bounding box calculation + """ + r = ChamferRectangle((0,0), 2, 2, 0.2, (True, True, False, False)) + xbounds, ybounds = r.bounding_box + assert_array_almost_equal(xbounds, (-1, 1)) + assert_array_almost_equal(ybounds, (-1, 1)) + r = ChamferRectangle((0,0), 2, 2, 0.2, (True, True, False, False), rotation=45) + xbounds, ybounds = r.bounding_box + assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) + assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + + +def test_round_rectangle_ctor(): + """ Test round rectangle creation + """ + test_cases = (((0,0), 1, 1, 0.2, (True, True, False, False)), + ((0, 0), 1, 2, 0.3, (True, True, True, True)), + ((1,1), 1, 2, 0.4, (False, False, False, False))) + for pos, width, height, radius, corners in test_cases: + r = RoundRectangle(pos, width, height, radius, corners) + assert_equal(r.position, pos) + assert_equal(r.width, width) + assert_equal(r.height, height) + assert_equal(r.radius, radius) + assert_array_almost_equal(r.corners, corners) + +def test_round_rectangle_bounds(): + """ Test round rectangle bounding box calculation + """ + r = RoundRectangle((0,0), 2, 2, 0.2, (True, True, False, False)) + xbounds, ybounds = r.bounding_box + assert_array_almost_equal(xbounds, (-1, 1)) + assert_array_almost_equal(ybounds, (-1, 1)) + r = RoundRectangle((0,0), 2, 2, 0.2, (True, True, False, False), rotation=45) + xbounds, ybounds = r.bounding_box + assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) + assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + + \ No newline at end of file -- cgit From d98d23f8b5d61bb9d20e743a3c44bf04b6b2330a Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Mon, 2 Feb 2015 00:43:08 -0500 Subject: More tests and bugfixes --- gerber/tests/test_primitives.py | 79 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 4 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index 4534484..e5ae770 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -165,6 +165,7 @@ def test_chamfer_rectangle_ctor(): assert_equal(r.chamfer, chamfer) assert_array_almost_equal(r.corners, corners) + def test_chamfer_rectangle_bounds(): """ Test chamfer rectangle bounding box calculation """ @@ -191,7 +192,8 @@ def test_round_rectangle_ctor(): assert_equal(r.height, height) assert_equal(r.radius, radius) assert_array_almost_equal(r.corners, corners) - + + def test_round_rectangle_bounds(): """ Test round rectangle bounding box calculation """ @@ -203,7 +205,76 @@ def test_round_rectangle_bounds(): xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + + +def test_obround_ctor(): + """ Test obround creation + """ + test_cases = (((0,0), 1, 1), + ((0, 0), 1, 2), + ((1,1), 1, 2)) + for pos, width, height in test_cases: + o = Obround(pos, width, height) + assert_equal(o.position, pos) + assert_equal(o.width, width) + assert_equal(o.height, height) + + +def test_obround_bounds(): + """ Test obround bounding box calculation + """ + o = Obround((2,2),2,4) + xbounds, ybounds = o.bounding_box + assert_array_almost_equal(xbounds, (1, 3)) + assert_array_almost_equal(ybounds, (0, 4)) + o = Obround((2,2),4,2) + xbounds, ybounds = o.bounding_box + assert_array_almost_equal(xbounds, (0, 4)) + assert_array_almost_equal(ybounds, (1, 3)) + + +def test_obround_orientation(): + o = Obround((0, 0), 2, 1) + assert_equal(o.orientation, 'horizontal') + o = Obround((0, 0), 1, 2) + assert_equal(o.orientation, 'vertical') + + +def test_obround_subshapes(): + o = Obround((0,0), 1, 4) + ss = o.subshapes + assert_array_almost_equal(ss['rectangle'].position, (0, 0)) + assert_array_almost_equal(ss['circle1'].position, (0, 1.5)) + assert_array_almost_equal(ss['circle2'].position, (0, -1.5)) + o = Obround((0,0), 4, 1) + ss = o.subshapes + assert_array_almost_equal(ss['rectangle'].position, (0, 0)) + assert_array_almost_equal(ss['circle1'].position, (1.5, 0)) + assert_array_almost_equal(ss['circle2'].position, (-1.5, 0)) - - - \ No newline at end of file +def test_polygon_ctor(): + """ Test polygon creation + """ + test_cases = (((0,0), 3, 5), + ((0, 0), 5, 6), + ((1,1), 7, 7)) + for pos, sides, radius in test_cases: + p = Polygon(pos, sides, radius) + assert_equal(p.position, pos) + assert_equal(p.sides, sides) + assert_equal(p.radius, radius) + +def test_polygon_bounds(): + """ Test polygon bounding box calculation + """ + p = Polygon((2,2), 3, 2) + xbounds, ybounds = p.bounding_box + assert_array_almost_equal(xbounds, (0, 4)) + assert_array_almost_equal(ybounds, (0, 4)) + p = Polygon((2,2),3, 4) + xbounds, ybounds = p.bounding_box + assert_array_almost_equal(xbounds, (-2, 6)) + assert_array_almost_equal(ybounds, (-2, 6)) + + + -- cgit From 1cc20b351c10b1fa19817f29edd8c54a27aeee4b Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Mon, 2 Feb 2015 11:42:47 -0500 Subject: tests --- gerber/tests/test_primitives.py | 119 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index e5ae770..14a3d39 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -6,6 +6,11 @@ from ..primitives import * from tests import * +def test_primitive_implementation_warning(): + p = Primitive() + assert_raises(NotImplementedError, p.bounding_box) + + def test_line_angle(): """ Test Line primitive angle calculation """ @@ -277,4 +282,118 @@ def test_polygon_bounds(): assert_array_almost_equal(ybounds, (-2, 6)) +def test_region_ctor(): + """ Test Region creation + """ + points = ((0, 0), (1,0), (1,1), (0,1)) + r = Region(points) + for i, point in enumerate(points): + assert_array_almost_equal(r.points[i], point) + + +def test_region_bounds(): + """ Test region bounding box calculation + """ + points = ((0, 0), (1,0), (1,1), (0,1)) + r = Region(points) + xbounds, ybounds = r.bounding_box + assert_array_almost_equal(xbounds, (0, 1)) + assert_array_almost_equal(ybounds, (0, 1)) + + +def test_round_butterfly_ctor(): + """ Test round butterfly creation + """ + test_cases = (((0,0), 3), ((0, 0), 5), ((1,1), 7)) + for pos, diameter in test_cases: + b = RoundButterfly(pos, diameter) + assert_equal(b.position, pos) + assert_equal(b.diameter, diameter) + assert_equal(b.radius, diameter/2.) + +def test_round_butterfly_ctor_validation(): + """ Test RoundButterfly argument validation + """ + assert_raises(TypeError, RoundButterfly, 3, 5) + assert_raises(TypeError, RoundButterfly, (3,4,5), 5) + +def test_round_butterfly_bounds(): + """ Test RoundButterfly bounding box calculation + """ + b = RoundButterfly((0, 0), 2) + xbounds, ybounds = b.bounding_box + assert_array_almost_equal(xbounds, (-1, 1)) + assert_array_almost_equal(ybounds, (-1, 1)) + +def test_square_butterfly_ctor(): + """ Test SquareButterfly creation + """ + test_cases = (((0,0), 3), ((0, 0), 5), ((1,1), 7)) + for pos, side in test_cases: + b = SquareButterfly(pos, side) + assert_equal(b.position, pos) + assert_equal(b.side, side) + +def test_square_butterfly_ctor_validation(): + """ Test SquareButterfly argument validation + """ + assert_raises(TypeError, SquareButterfly, 3, 5) + assert_raises(TypeError, SquareButterfly, (3,4,5), 5) + +def test_square_butterfly_bounds(): + """ Test SquareButterfly bounding box calculation + """ + b = SquareButterfly((0, 0), 2) + xbounds, ybounds = b.bounding_box + assert_array_almost_equal(xbounds, (-1, 1)) + assert_array_almost_equal(ybounds, (-1, 1)) + +def test_donut_ctor(): + """ Test Donut primitive creation + """ + test_cases = (((0,0), 'round', 3, 5), ((0, 0), 'square', 5, 7), + ((1,1), 'hexagon', 7, 9), ((2, 2), 'octagon', 9, 11)) + for pos, shape, in_d, out_d in test_cases: + d = Donut(pos, shape, in_d, out_d) + assert_equal(d.position, pos) + assert_equal(d.shape, shape) + assert_equal(d.inner_diameter, in_d) + assert_equal(d.outer_diameter, out_d) + +def test_donut_ctor_validation(): + assert_raises(TypeError, Donut, 3, 'round', 5, 7) + assert_raises(TypeError, Donut, (3, 4, 5), 'round', 5, 7) + assert_raises(ValueError, Donut, (0, 0), 'triangle', 3, 5) + assert_raises(ValueError, Donut, (0, 0), 'round', 5, 3) + +def test_donut_bounds(): + pass + +def test_drill_ctor(): + """ Test drill primitive creation + """ + test_cases = (((0, 0), 2), ((1, 1), 3), ((2, 2), 5)) + for position, diameter in test_cases: + d = Drill(position, diameter) + assert_equal(d.position, position) + assert_equal(d.diameter, diameter) + assert_equal(d.radius, diameter/2.) + +def test_drill_ctor_validation(): + """ Test drill argument validation + """ + assert_raises(TypeError, Drill, 3, 5) + assert_raises(TypeError, Drill, (3,4,5), 5) + +def test_drill_bounds(): + d = Drill((0, 0), 2) + xbounds, ybounds = d.bounding_box + assert_array_almost_equal(xbounds, (-1, 1)) + assert_array_almost_equal(ybounds, (-1, 1)) + d = Drill((1, 2), 2) + xbounds, ybounds = d.bounding_box + assert_array_almost_equal(xbounds, (0, 2)) + assert_array_almost_equal(ybounds, (1, 3)) + + \ No newline at end of file -- cgit From 8f69c1dfa281b6486c8fce16c1d58acef70c7ae7 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 12 Feb 2015 11:28:50 -0500 Subject: Update line primitive to take aperture parameter This fixes the exception referenced in #12. Still need to add rendering code for rectangle aperture lines and arcs. Rectangle strokes will be drawn as polygons by the rendering backends. --- gerber/tests/test_primitives.py | 44 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index 14a3d39..912cebb 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -27,17 +27,17 @@ def test_line_angle(): line_angle = (l.angle + 2 * math.pi) % (2 * math.pi) assert_almost_equal(line_angle, expected) - -def test_line_bounds(): - """ Test Line primitive bounding box calculation - """ - cases = [((0, 0), (1, 1), ((0, 1), (0, 1))), - ((-1, -1), (1, 1), ((-1, 1), (-1, 1))), - ((1, 1), (-1, -1), ((-1, 1), (-1, 1))), - ((-1, 1), (1, -1), ((-1, 1), (-1, 1))),] - for start, end, expected in cases: - l = Line(start, end, 0) - assert_equal(l.bounding_box, expected) +# Need to update bounds calculation using aperture +#def test_line_bounds(): +# """ Test Line primitive bounding box calculation +# """ +# cases = [((0, 0), (1, 1), ((0, 1), (0, 1))), +# ((-1, -1), (1, 1), ((-1, 1), (-1, 1))), +# ((1, 1), (-1, -1), ((-1, 1), (-1, 1))), +# ((-1, 1), (1, -1), ((-1, 1), (-1, 1))),] +# for start, end, expected in cases: +# l = Line(start, end, 0) +# assert_equal(l.bounding_box, expected) def test_arc_radius(): @@ -63,17 +63,17 @@ def test_arc_sweep_angle(): a = Arc(start, end, center, direction, 0) assert_equal(a.sweep_angle, sweep) - -def test_arc_bounds(): - """ Test Arc primitive bounding box calculation - """ - cases = [((1, 0), (0, 1), (0, 0), 'clockwise', ((-1, 1), (-1, 1))), - ((1, 0), (0, 1), (0, 0), 'counterclockwise', ((0, 1), (0, 1))), - #TODO: ADD MORE TEST CASES HERE - ] - for start, end, center, direction, bounds in cases: - a = Arc(start, end, center, direction, 0) - assert_equal(a.bounding_box, bounds) +# Need to update bounds calculation using aperture +#def test_arc_bounds(): +# """ Test Arc primitive bounding box calculation +# """ +# cases = [((1, 0), (0, 1), (0, 0), 'clockwise', ((-1, 1), (-1, 1))), +# ((1, 0), (0, 1), (0, 0), 'counterclockwise', ((0, 1), (0, 1))), +# #TODO: ADD MORE TEST CASES HERE +# ] +# for start, end, center, direction, bounds in cases: +# a = Arc(start, end, center, direction, 0) +# assert_equal(a.bounding_box, bounds) def test_circle_radius(): -- cgit From 5e23d07bcb5103b4607c6ad591a2a547c97ee1f6 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Fri, 13 Feb 2015 09:37:27 -0500 Subject: Fix rendering for line with rectangular aperture per #12. Still need to do the same for arcs. --- gerber/tests/test_primitives.py | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index 912cebb..877823d 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -27,17 +27,30 @@ def test_line_angle(): line_angle = (l.angle + 2 * math.pi) % (2 * math.pi) assert_almost_equal(line_angle, expected) -# Need to update bounds calculation using aperture -#def test_line_bounds(): -# """ Test Line primitive bounding box calculation -# """ -# cases = [((0, 0), (1, 1), ((0, 1), (0, 1))), -# ((-1, -1), (1, 1), ((-1, 1), (-1, 1))), -# ((1, 1), (-1, -1), ((-1, 1), (-1, 1))), -# ((-1, 1), (1, -1), ((-1, 1), (-1, 1))),] -# for start, end, expected in cases: -# l = Line(start, end, 0) -# assert_equal(l.bounding_box, expected) +def test_line_bounds(): + """ Test Line primitive bounding box calculation + """ + cases = [((0, 0), (1, 1), ((-1, 2), (-1, 2))), + ((-1, -1), (1, 1), ((-2, 2), (-2, 2))), + ((1, 1), (-1, -1), ((-2, 2), (-2, 2))), + ((-1, 1), (1, -1), ((-2, 2), (-2, 2))),] + + c = Circle((0, 0), 2) + r = Rectangle((0, 0), 2, 2) + for shape in (c, r): + for start, end, expected in cases: + l = Line(start, end, shape) + assert_equal(l.bounding_box, expected) + # Test a non-square rectangle + r = Rectangle((0, 0), 3, 2) + cases = [((0, 0), (1, 1), ((-1.5, 2.5), (-1, 2))), + ((-1, -1), (1, 1), ((-2.5, 2.5), (-2, 2))), + ((1, 1), (-1, -1), ((-2.5, 2.5), (-2, 2))), + ((-1, 1), (1, -1), ((-2.5, 2.5), (-2, 2))),] + for start, end, expected in cases: + l = Line(start, end, r) + assert_equal(l.bounding_box, expected) + def test_arc_radius(): -- cgit From 5cf1fa74b42eb8feaab23078bef6f31f6d647c33 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 15 Feb 2015 02:20:02 -0500 Subject: Tests and bugfixes --- gerber/tests/test_primitives.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index 877823d..f8b8620 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -73,20 +73,21 @@ def test_arc_sweep_angle(): ((1, 0), (-1, 0), (0, 0), 'counterclockwise', math.radians(180)),] for start, end, center, direction, sweep in cases: - a = Arc(start, end, center, direction, 0) + c = Circle((0,0), 1) + a = Arc(start, end, center, direction, c) assert_equal(a.sweep_angle, sweep) -# Need to update bounds calculation using aperture -#def test_arc_bounds(): -# """ Test Arc primitive bounding box calculation -# """ -# cases = [((1, 0), (0, 1), (0, 0), 'clockwise', ((-1, 1), (-1, 1))), -# ((1, 0), (0, 1), (0, 0), 'counterclockwise', ((0, 1), (0, 1))), -# #TODO: ADD MORE TEST CASES HERE -# ] -# for start, end, center, direction, bounds in cases: -# a = Arc(start, end, center, direction, 0) -# assert_equal(a.bounding_box, bounds) +def test_arc_bounds(): + """ Test Arc primitive bounding box calculation + """ + cases = [((1, 0), (0, 1), (0, 0), 'clockwise', ((-1.5, 1.5), (-1.5, 1.5))), + ((1, 0), (0, 1), (0, 0), 'counterclockwise', ((-0.5, 1.5), (-0.5, 1.5))), + #TODO: ADD MORE TEST CASES HERE + ] + for start, end, center, direction, bounds in cases: + c = Circle((0,0), 1) + a = Arc(start, end, center, direction, c) + assert_equal(a.bounding_box, bounds) def test_circle_radius(): -- cgit From 288ac27084b47166ac662402ea340d0aa25d8f56 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Wed, 18 Feb 2015 04:31:23 -0500 Subject: Get unit conversion working for Gerber/Excellon files Started operations module for file operations/transforms --- gerber/tests/test_primitives.py | 235 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 223 insertions(+), 12 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index f8b8620..cada6d4 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -51,6 +51,57 @@ def test_line_bounds(): l = Line(start, end, r) assert_equal(l.bounding_box, expected) +def test_line_vertices(): + c = Circle((0, 0), 2) + l = Line((0, 0), (1, 1), c) + assert_equal(l.vertices, None) + + # All 4 compass points, all 4 quadrants and the case where start == end + test_cases = [((0, 0), (1, 0), ((-1, -1), (-1, 1), (2, 1), (2, -1))), + ((0, 0), (1, 1), ((-1, -1), (-1, 1), (0, 2), (2, 2), (2, 0), (1,-1))), + ((0, 0), (0, 1), ((-1, -1), (-1, 2), (1, 2), (1, -1))), + ((0, 0), (-1, 1), ((-1, -1), (-2, 0), (-2, 2), (0, 2), (1, 1), (1, -1))), + ((0, 0), (-1, 0), ((-2, -1), (-2, 1), (1, 1), (1, -1))), + ((0, 0), (-1, -1), ((-2, -2), (1, -1), (1, 1), (-1, 1), (-2, 0), (0,-2))), + ((0, 0), (0, -1), ((-1, -2), (-1, 1), (1, 1), (1, -2))), + ((0, 0), (1, -1), ((-1, -1), (0, -2), (2, -2), (2, 0), (1, 1), (-1, 1))), + ((0, 0), (0, 0), ((-1, -1), (-1, 1), (1, 1), (1, -1))),] + r = Rectangle((0, 0), 2, 2) + + for start, end, vertices in test_cases: + l = Line(start, end, r) + assert_equal(set(vertices), set(l.vertices)) + +def test_line_conversion(): + c = Circle((0, 0), 25.4) + l = Line((2.54, 25.4), (254.0, 2540.0), c) + l.to_inch() + assert_equal(l.start, (0.1, 1.0)) + assert_equal(l.end, (10.0, 100.0)) + assert_equal(l.aperture.diameter, 1.0) + + c = Circle((0, 0), 1.0) + l = Line((0.1, 1.0), (10.0, 100.0), c) + l.to_metric() + assert_equal(l.start, (2.54, 25.4)) + assert_equal(l.end, (254.0, 2540.0)) + assert_equal(l.aperture.diameter, 25.4) + + r = Rectangle((0, 0), 25.4, 254.0) + l = Line((2.54, 25.4), (254.0, 2540.0), r) + l.to_inch() + assert_equal(l.start, (0.1, 1.0)) + assert_equal(l.end, (10.0, 100.0)) + assert_equal(l.aperture.width, 1.0) + assert_equal(l.aperture.height, 10.0) + + r = Rectangle((0, 0), 1.0, 10.0) + l = Line((0.1, 1.0), (10.0, 100.0), r) + l.to_metric() + assert_equal(l.start, (2.54, 25.4)) + assert_equal(l.end, (254.0, 2540.0)) + assert_equal(l.aperture.width, 25.4) + assert_equal(l.aperture.height, 254.0) def test_arc_radius(): @@ -89,6 +140,24 @@ def test_arc_bounds(): a = Arc(start, end, center, direction, c) assert_equal(a.bounding_box, bounds) +def test_arc_conversion(): + c = Circle((0, 0), 25.4) + a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0),'clockwise', c) + a.to_inch() + assert_equal(a.start, (0.1, 1.0)) + assert_equal(a.end, (10.0, 100.0)) + assert_equal(a.center, (1000.0, 10000.0)) + assert_equal(a.aperture.diameter, 1.0) + + c = Circle((0, 0), 1.0) + a = Arc((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0),'clockwise', c) + a.to_metric() + assert_equal(a.start, (2.54, 25.4)) + assert_equal(a.end, (254.0, 2540.0)) + assert_equal(a.center, (25400.0, 254000.0)) + assert_equal(a.aperture.diameter, 25.4) + + def test_circle_radius(): """ Test Circle primitive radius calculation @@ -146,7 +215,7 @@ def test_rectangle_bounds(): xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) - + def test_diamond_ctor(): """ Test diamond creation """ @@ -169,6 +238,19 @@ def test_diamond_bounds(): assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) +def test_diamond_conversion(): + d = Diamond((2.54, 25.4), 254.0, 2540.0) + d.to_inch() + assert_equal(d.position, (0.1, 1.0)) + assert_equal(d.width, 10.0) + assert_equal(d.height, 100.0) + + d = Diamond((0.1, 1.0), 10.0, 100.0) + d.to_metric() + assert_equal(d.position, (2.54, 25.4)) + assert_equal(d.width, 254.0) + assert_equal(d.height, 2540.0) + def test_chamfer_rectangle_ctor(): """ Test chamfer rectangle creation @@ -198,6 +280,21 @@ def test_chamfer_rectangle_bounds(): assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) +def test_chamfer_rectangle_conversion(): + r = ChamferRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False)) + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + assert_equal(r.height, 100.0) + assert_equal(r.chamfer, 0.01) + + r = ChamferRectangle((0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False)) + r.to_metric() + assert_equal(r.position, (2.54,25.4)) + assert_equal(r.width, 254.0) + assert_equal(r.height, 2540.0) + assert_equal(r.chamfer, 0.254) + def test_round_rectangle_ctor(): """ Test round rectangle creation """ @@ -226,6 +323,21 @@ def test_round_rectangle_bounds(): assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) +def test_round_rectangle_conversion(): + r = RoundRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False)) + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + assert_equal(r.height, 100.0) + assert_equal(r.radius, 0.01) + + r = RoundRectangle((0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False)) + r.to_metric() + assert_equal(r.position, (2.54,25.4)) + assert_equal(r.width, 254.0) + assert_equal(r.height, 2540.0) + assert_equal(r.radius, 0.254) + def test_obround_ctor(): """ Test obround creation """ @@ -270,7 +382,22 @@ def test_obround_subshapes(): assert_array_almost_equal(ss['rectangle'].position, (0, 0)) assert_array_almost_equal(ss['circle1'].position, (1.5, 0)) assert_array_almost_equal(ss['circle2'].position, (-1.5, 0)) - + + +def test_obround_conversion(): + o = Obround((2.54,25.4), 254.0, 2540.0) + o.to_inch() + assert_equal(o.position, (0.1, 1.0)) + assert_equal(o.width, 10.0) + assert_equal(o.height, 100.0) + + o= Obround((0.1, 1.0), 10.0, 100.0) + o.to_metric() + assert_equal(o.position, (2.54, 25.4)) + assert_equal(o.width, 254.0) + assert_equal(o.height, 2540.0) + + def test_polygon_ctor(): """ Test polygon creation """ @@ -282,7 +409,7 @@ def test_polygon_ctor(): assert_equal(p.position, pos) assert_equal(p.sides, sides) assert_equal(p.radius, radius) - + def test_polygon_bounds(): """ Test polygon bounding box calculation """ @@ -296,6 +423,18 @@ def test_polygon_bounds(): assert_array_almost_equal(ybounds, (-2, 6)) +def test_polygon_conversion(): + p = Polygon((2.54, 25.4), 3, 254.0) + p.to_inch() + assert_equal(p.position, (0.1, 1.0)) + assert_equal(p.radius, 10.0) + + p = Polygon((0.1, 1.0), 3, 10.0) + p.to_metric() + assert_equal(p.position, (2.54, 25.4)) + assert_equal(p.radius, 254.0) + + def test_region_ctor(): """ Test Region creation """ @@ -313,8 +452,20 @@ def test_region_bounds(): xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (0, 1)) assert_array_almost_equal(ybounds, (0, 1)) - - + +def test_region_conversion(): + points = ((2.54, 25.4), (254.0,2540.0), (25400.0,254000.0), (2.54,25.4)) + r = Region(points) + r.to_inch() + assert_equal(set(r.points), {(0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0)}) + + points = ((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0), (0.1, 1.0)) + r = Region(points) + r.to_metric() + assert_equal(set(r.points), {(2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0)}) + + + def test_round_butterfly_ctor(): """ Test round butterfly creation """ @@ -331,6 +482,18 @@ def test_round_butterfly_ctor_validation(): assert_raises(TypeError, RoundButterfly, 3, 5) assert_raises(TypeError, RoundButterfly, (3,4,5), 5) + +def test_round_butterfly_conversion(): + b = RoundButterfly((2.54, 25.4), 254.0) + b.to_inch() + assert_equal(b.position, (0.1, 1.0)) + assert_equal(b.diameter, 10.0) + + b = RoundButterfly((0.1, 1.0), 10.0) + b.to_metric() + assert_equal(b.position, (2.54, 25.4)) + assert_equal(b.diameter, (254.0)) + def test_round_butterfly_bounds(): """ Test RoundButterfly bounding box calculation """ @@ -338,7 +501,7 @@ def test_round_butterfly_bounds(): xbounds, ybounds = b.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) - + def test_square_butterfly_ctor(): """ Test SquareButterfly creation """ @@ -363,6 +526,17 @@ def test_square_butterfly_bounds(): assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) +def test_squarebutterfly_conversion(): + b = SquareButterfly((2.54, 25.4), 254.0) + b.to_inch() + assert_equal(b.position, (0.1, 1.0)) + assert_equal(b.side, 10.0) + + b = SquareButterfly((0.1, 1.0), 10.0) + b.to_metric() + assert_equal(b.position, (2.54, 25.4)) + assert_equal(b.side, (254.0)) + def test_donut_ctor(): """ Test Donut primitive creation """ @@ -380,9 +554,28 @@ def test_donut_ctor_validation(): assert_raises(TypeError, Donut, (3, 4, 5), 'round', 5, 7) assert_raises(ValueError, Donut, (0, 0), 'triangle', 3, 5) assert_raises(ValueError, Donut, (0, 0), 'round', 5, 3) - + def test_donut_bounds(): - pass + d = Donut((0, 0), 'round', 0.0, 2.0) + assert_equal(d.lower_left, (-1.0, -1.0)) + assert_equal(d.upper_right, (1.0, 1.0)) + xbounds, ybounds = d.bounding_box + assert_equal(xbounds, (-1., 1.)) + assert_equal(ybounds, (-1., 1.)) + +def test_donut_conversion(): + d = Donut((2.54, 25.4), 'round', 254.0, 2540.0) + d.to_inch() + assert_equal(d.position, (0.1, 1.0)) + assert_equal(d.inner_diameter, 10.0) + assert_equal(d.outer_diaemter, 100.0) + + d = Donut((0.1, 1.0), 'round', 10.0, 100.0) + d.to_metric() + assert_equal(d.position, (2.54, 25.4)) + assert_equal(d.inner_diameter, 254.0) + assert_equal(d.outer_diaemter, 2540.0) + def test_drill_ctor(): """ Test drill primitive creation @@ -393,13 +586,15 @@ def test_drill_ctor(): assert_equal(d.position, position) assert_equal(d.diameter, diameter) assert_equal(d.radius, diameter/2.) - + + def test_drill_ctor_validation(): """ Test drill argument validation """ assert_raises(TypeError, Drill, 3, 5) assert_raises(TypeError, Drill, (3,4,5), 5) - + + def test_drill_bounds(): d = Drill((0, 0), 2) xbounds, ybounds = d.bounding_box @@ -409,5 +604,21 @@ def test_drill_bounds(): xbounds, ybounds = d.bounding_box assert_array_almost_equal(xbounds, (0, 2)) assert_array_almost_equal(ybounds, (1, 3)) - - \ No newline at end of file + +def test_drill_conversion(): + d = Drill((2.54, 25.4), 254.) + d.to_inch() + assert_equal(d.position, (0.1, 1.0)) + assert_equal(d.diameter, 10.0) + + d = Drill((0.1, 1.0), 10.) + d.to_metric() + assert_equal(d.position, (2.54, 25.4)) + assert_equal(d.diameter, 254.0) + +def test_drill_equality(): + d = Drill((2.54, 25.4), 254.) + d1 = Drill((2.54, 25.4), 254.) + assert_equal(d, d1) + d1 = Drill((2.54, 25.4), 254.2) + assert_not_equal(d, d1) -- cgit From 7ace94b0230e9acd85097c1812840250d551015c Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Wed, 18 Feb 2015 15:35:01 +0100 Subject: Make gerber.render a package & fix more relative import statements --- gerber/tests/test_primitives.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index cada6d4..dab0225 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -3,7 +3,7 @@ # Author: Hamilton Kibbe from ..primitives import * -from tests import * +from .tests import * def test_primitive_implementation_warning(): -- cgit From 5966d7830bda7f37ed5ddcc1bfccb93e7f780eaa Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Wed, 18 Feb 2015 23:13:23 -0500 Subject: Add offset operation --- gerber/tests/test_primitives.py | 166 +++++++++++++++++++++++++++++++++++----- 1 file changed, 145 insertions(+), 21 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index dab0225..2909d8f 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -6,10 +6,12 @@ from ..primitives import * from .tests import * -def test_primitive_implementation_warning(): +def test_primitive_smoketest(): p = Primitive() assert_raises(NotImplementedError, p.bounding_box) - + p.to_metric() + p.to_inch() + p.offset(1, 1) def test_line_angle(): """ Test Line primitive angle calculation @@ -103,6 +105,15 @@ def test_line_conversion(): assert_equal(l.aperture.width, 25.4) assert_equal(l.aperture.height, 254.0) +def test_line_offset(): + c = Circle((0, 0), 1) + l = Line((0, 0), (1, 1), c) + l.offset(1, 0) + assert_equal(l.start,(1., 0.)) + assert_equal(l.end, (2., 1.)) + l.offset(0, 1) + assert_equal(l.start,(1., 1.)) + assert_equal(l.end, (2., 2.)) def test_arc_radius(): """ Test Arc primitive radius calculation @@ -114,7 +125,6 @@ def test_arc_radius(): a = Arc(start, end, center, 'clockwise', 0) assert_equal(a.radius, radius) - def test_arc_sweep_angle(): """ Test Arc primitive sweep angle calculation """ @@ -157,7 +167,17 @@ def test_arc_conversion(): assert_equal(a.center, (25400.0, 254000.0)) assert_equal(a.aperture.diameter, 25.4) - +def test_arc_offset(): + c = Circle((0, 0), 1) + a = Arc((0, 0), (1, 1), (2, 2), 'clockwise', c) + a.offset(1, 0) + assert_equal(a.start,(1., 0.)) + assert_equal(a.end, (2., 1.)) + assert_equal(a.center, (3., 2.)) + a.offset(0, 1) + assert_equal(a.start,(1., 1.)) + assert_equal(a.end, (2., 2.)) + assert_equal(a.center, (3., 3.)) def test_circle_radius(): """ Test Circle primitive radius calculation @@ -165,13 +185,28 @@ def test_circle_radius(): c = Circle((1, 1), 2) assert_equal(c.radius, 1) - def test_circle_bounds(): """ Test Circle bounding box calculation """ c = Circle((1, 1), 2) assert_equal(c.bounding_box, ((0, 2), (0, 2))) +def test_circle_conversion(): + c = Circle((2.54, 25.4), 254.0) + c.to_inch() + assert_equal(c.position, (0.1, 1.)) + assert_equal(c.diameter, 10.) + c = Circle((0.1, 1.0), 10.0) + c.to_metric() + assert_equal(c.position, (2.54, 25.4)) + assert_equal(c.diameter, 254.) + +def test_circle_offset(): + c = Circle((0, 0), 1) + c.offset(1, 0) + assert_equal(c.position,(1., 0.)) + c.offset(0, 1) + assert_equal(c.position,(1., 1.)) def test_ellipse_ctor(): """ Test ellipse creation @@ -181,7 +216,6 @@ def test_ellipse_ctor(): assert_equal(e.width, 3) assert_equal(e.height, 2) - def test_ellipse_bounds(): """ Test ellipse bounding box calculation """ @@ -194,6 +228,26 @@ def test_ellipse_bounds(): e = Ellipse((2, 2), 4, 2, rotation=270) assert_equal(e.bounding_box, ((1, 3), (0, 4))) +def test_ellipse_conversion(): + e = Ellipse((2.54, 25.4), 254.0, 2540.) + e.to_inch() + assert_equal(e.position, (0.1, 1.)) + assert_equal(e.width, 10.) + assert_equal(e.height, 100.) + + e = Ellipse((0.1, 1.), 10.0, 100.) + e.to_metric() + assert_equal(e.position, (2.54, 25.4)) + assert_equal(e.width, 254.) + assert_equal(e.height, 2540.) + +def test_ellipse_offset(): + e = Ellipse((0, 0), 1, 2) + e.offset(1, 0) + assert_equal(e.position,(1., 0.)) + e.offset(0, 1) + assert_equal(e.position,(1., 1.)) + def test_rectangle_ctor(): """ Test rectangle creation """ @@ -216,6 +270,25 @@ def test_rectangle_bounds(): assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) +def test_rectangle_conversion(): + r = Rectangle((2.54, 25.4), 254.0, 2540.0) + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + assert_equal(r.height, 100.0) + r = Rectangle((0.1, 1.0), 10.0, 100.0) + r.to_metric() + assert_equal(r.position, (2.54,25.4)) + assert_equal(r.width, 254.0) + assert_equal(r.height, 2540.0) + +def test_rectangle_offset(): + r = Rectangle((0, 0), 1, 2) + r.offset(1, 0) + assert_equal(r.position,(1., 0.)) + r.offset(0, 1) + assert_equal(r.position,(1., 1.)) + def test_diamond_ctor(): """ Test diamond creation """ @@ -251,6 +324,12 @@ def test_diamond_conversion(): assert_equal(d.width, 254.0) assert_equal(d.height, 2540.0) +def test_diamond_offset(): + d = Diamond((0, 0), 1, 2) + d.offset(1, 0) + assert_equal(d.position,(1., 0.)) + d.offset(0, 1) + assert_equal(d.position,(1., 1.)) def test_chamfer_rectangle_ctor(): """ Test chamfer rectangle creation @@ -266,7 +345,6 @@ def test_chamfer_rectangle_ctor(): assert_equal(r.chamfer, chamfer) assert_array_almost_equal(r.corners, corners) - def test_chamfer_rectangle_bounds(): """ Test chamfer rectangle bounding box calculation """ @@ -279,7 +357,6 @@ def test_chamfer_rectangle_bounds(): assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) - def test_chamfer_rectangle_conversion(): r = ChamferRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False)) r.to_inch() @@ -295,6 +372,13 @@ def test_chamfer_rectangle_conversion(): assert_equal(r.height, 2540.0) assert_equal(r.chamfer, 0.254) +def test_chamfer_rectangle_offset(): + r = ChamferRectangle((0, 0), 1, 2, 0.01, (True, True, False, False)) + r.offset(1, 0) + assert_equal(r.position,(1., 0.)) + r.offset(0, 1) + assert_equal(r.position,(1., 1.)) + def test_round_rectangle_ctor(): """ Test round rectangle creation """ @@ -309,7 +393,6 @@ def test_round_rectangle_ctor(): assert_equal(r.radius, radius) assert_array_almost_equal(r.corners, corners) - def test_round_rectangle_bounds(): """ Test round rectangle bounding box calculation """ @@ -322,7 +405,6 @@ def test_round_rectangle_bounds(): assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) - def test_round_rectangle_conversion(): r = RoundRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False)) r.to_inch() @@ -338,6 +420,13 @@ def test_round_rectangle_conversion(): assert_equal(r.height, 2540.0) assert_equal(r.radius, 0.254) +def test_round_rectangle_offset(): + r = RoundRectangle((0, 0), 1, 2, 0.01, (True, True, False, False)) + r.offset(1, 0) + assert_equal(r.position,(1., 0.)) + r.offset(0, 1) + assert_equal(r.position,(1., 1.)) + def test_obround_ctor(): """ Test obround creation """ @@ -350,7 +439,6 @@ def test_obround_ctor(): assert_equal(o.width, width) assert_equal(o.height, height) - def test_obround_bounds(): """ Test obround bounding box calculation """ @@ -363,14 +451,12 @@ def test_obround_bounds(): assert_array_almost_equal(xbounds, (0, 4)) assert_array_almost_equal(ybounds, (1, 3)) - def test_obround_orientation(): o = Obround((0, 0), 2, 1) assert_equal(o.orientation, 'horizontal') o = Obround((0, 0), 1, 2) assert_equal(o.orientation, 'vertical') - def test_obround_subshapes(): o = Obround((0,0), 1, 4) ss = o.subshapes @@ -383,7 +469,6 @@ def test_obround_subshapes(): assert_array_almost_equal(ss['circle1'].position, (1.5, 0)) assert_array_almost_equal(ss['circle2'].position, (-1.5, 0)) - def test_obround_conversion(): o = Obround((2.54,25.4), 254.0, 2540.0) o.to_inch() @@ -397,6 +482,12 @@ def test_obround_conversion(): assert_equal(o.width, 254.0) assert_equal(o.height, 2540.0) +def test_obround_offset(): + o = Obround((0, 0), 1, 2) + o.offset(1, 0) + assert_equal(o.position,(1., 0.)) + o.offset(0, 1) + assert_equal(o.position,(1., 1.)) def test_polygon_ctor(): """ Test polygon creation @@ -422,7 +513,6 @@ def test_polygon_bounds(): assert_array_almost_equal(xbounds, (-2, 6)) assert_array_almost_equal(ybounds, (-2, 6)) - def test_polygon_conversion(): p = Polygon((2.54, 25.4), 3, 254.0) p.to_inch() @@ -434,6 +524,12 @@ def test_polygon_conversion(): assert_equal(p.position, (2.54, 25.4)) assert_equal(p.radius, 254.0) +def test_polygon_offset(): + p = Polygon((0, 0), 5, 10) + p.offset(1, 0) + assert_equal(p.position,(1., 0.)) + p.offset(0, 1) + assert_equal(p.position,(1., 1.)) def test_region_ctor(): """ Test Region creation @@ -443,7 +539,6 @@ def test_region_ctor(): for i, point in enumerate(points): assert_array_almost_equal(r.points[i], point) - def test_region_bounds(): """ Test region bounding box calculation """ @@ -464,7 +559,13 @@ def test_region_conversion(): r.to_metric() assert_equal(set(r.points), {(2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0)}) - +def test_region_offset(): + points = ((0, 0), (1,0), (1,1), (0,1)) + r = Region(points) + r.offset(1, 0) + assert_equal(set(r.points), {(1, 0), (2, 0), (2,1), (1, 1)}) + r.offset(0, 1) + assert_equal(set(r.points), {(1, 1), (2, 1), (2,2), (1, 2)}) def test_round_butterfly_ctor(): """ Test round butterfly creation @@ -482,7 +583,6 @@ def test_round_butterfly_ctor_validation(): assert_raises(TypeError, RoundButterfly, 3, 5) assert_raises(TypeError, RoundButterfly, (3,4,5), 5) - def test_round_butterfly_conversion(): b = RoundButterfly((2.54, 25.4), 254.0) b.to_inch() @@ -494,6 +594,13 @@ def test_round_butterfly_conversion(): assert_equal(b.position, (2.54, 25.4)) assert_equal(b.diameter, (254.0)) +def test_round_butterfly_offset(): + b = RoundButterfly((0, 0), 1) + b.offset(1, 0) + assert_equal(b.position,(1., 0.)) + b.offset(0, 1) + assert_equal(b.position,(1., 1.)) + def test_round_butterfly_bounds(): """ Test RoundButterfly bounding box calculation """ @@ -517,7 +624,6 @@ def test_square_butterfly_ctor_validation(): assert_raises(TypeError, SquareButterfly, 3, 5) assert_raises(TypeError, SquareButterfly, (3,4,5), 5) - def test_square_butterfly_bounds(): """ Test SquareButterfly bounding box calculation """ @@ -537,6 +643,13 @@ def test_squarebutterfly_conversion(): assert_equal(b.position, (2.54, 25.4)) assert_equal(b.side, (254.0)) +def test_square_butterfly_offset(): + b = SquareButterfly((0, 0), 1) + b.offset(1, 0) + assert_equal(b.position,(1., 0.)) + b.offset(0, 1) + assert_equal(b.position,(1., 1.)) + def test_donut_ctor(): """ Test Donut primitive creation """ @@ -576,6 +689,12 @@ def test_donut_conversion(): assert_equal(d.inner_diameter, 254.0) assert_equal(d.outer_diaemter, 2540.0) +def test_donut_offset(): + d = Donut((0, 0), 'round', 1, 10) + d.offset(1, 0) + assert_equal(d.position,(1., 0.)) + d.offset(0, 1) + assert_equal(d.position,(1., 1.)) def test_drill_ctor(): """ Test drill primitive creation @@ -587,14 +706,12 @@ def test_drill_ctor(): assert_equal(d.diameter, diameter) assert_equal(d.radius, diameter/2.) - def test_drill_ctor_validation(): """ Test drill argument validation """ assert_raises(TypeError, Drill, 3, 5) assert_raises(TypeError, Drill, (3,4,5), 5) - def test_drill_bounds(): d = Drill((0, 0), 2) xbounds, ybounds = d.bounding_box @@ -616,6 +733,13 @@ def test_drill_conversion(): assert_equal(d.position, (2.54, 25.4)) assert_equal(d.diameter, 254.0) +def test_drill_offset(): + d = Drill((0, 0), 1.) + d.offset(1, 0) + assert_equal(d.position,(1., 0.)) + d.offset(0, 1) + assert_equal(d.position,(1., 1.)) + def test_drill_equality(): d = Drill((2.54, 25.4), 254.) d1 = Drill((2.54, 25.4), 254.) -- cgit From 68619d4d5a7beb38dc81d953b43bf4196ca1d3a6 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 5 Mar 2015 22:42:42 -0500 Subject: Fix parsing for multiline ipc-d-356 records --- gerber/tests/test_primitives.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index 2909d8f..f3b1189 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -681,13 +681,13 @@ def test_donut_conversion(): d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.inner_diameter, 10.0) - assert_equal(d.outer_diaemter, 100.0) + assert_equal(d.outer_diameter, 100.0) d = Donut((0.1, 1.0), 'round', 10.0, 100.0) d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.inner_diameter, 254.0) - assert_equal(d.outer_diaemter, 2540.0) + assert_equal(d.outer_diameter, 2540.0) def test_donut_offset(): d = Donut((0, 0), 'round', 1, 10) -- cgit From 390838fc8b70c9b105fdc1d3e35a4533b27faa83 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Fri, 24 Apr 2015 10:54:13 -0400 Subject: Fix for #25. Checking was happening at the gerber/excellon file level, but I added units checking at the primitive level so the use case shown in the example is covered. Might want to throw a bunch more assertions in the test code (i started doing a few) to cover multiple calls to unit conversion functions --- gerber/tests/test_primitives.py | 115 +++++++++++++++++++++++++++------------- 1 file changed, 77 insertions(+), 38 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index f3b1189..c438735 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -75,30 +75,57 @@ def test_line_vertices(): assert_equal(set(vertices), set(l.vertices)) def test_line_conversion(): - c = Circle((0, 0), 25.4) - l = Line((2.54, 25.4), (254.0, 2540.0), c) + c = Circle((0, 0), 25.4, units='metric') + l = Line((2.54, 25.4), (254.0, 2540.0), c, units='metric') + + # No effect + l.to_metric() + assert_equal(l.start, (2.54, 25.4)) + assert_equal(l.end, (254.0, 2540.0)) + assert_equal(l.aperture.diameter, 25.4) + + l.to_inch() + assert_equal(l.start, (0.1, 1.0)) + assert_equal(l.end, (10.0, 100.0)) + assert_equal(l.aperture.diameter, 1.0) + + # No effect l.to_inch() assert_equal(l.start, (0.1, 1.0)) assert_equal(l.end, (10.0, 100.0)) assert_equal(l.aperture.diameter, 1.0) - c = Circle((0, 0), 1.0) - l = Line((0.1, 1.0), (10.0, 100.0), c) + c = Circle((0, 0), 1.0, units='inch') + l = Line((0.1, 1.0), (10.0, 100.0), c, units='inch') + + # No effect + l.to_inch() + assert_equal(l.start, (0.1, 1.0)) + assert_equal(l.end, (10.0, 100.0)) + assert_equal(l.aperture.diameter, 1.0) + + + l.to_metric() + assert_equal(l.start, (2.54, 25.4)) + assert_equal(l.end, (254.0, 2540.0)) + assert_equal(l.aperture.diameter, 25.4) + + #No effect l.to_metric() assert_equal(l.start, (2.54, 25.4)) assert_equal(l.end, (254.0, 2540.0)) assert_equal(l.aperture.diameter, 25.4) - r = Rectangle((0, 0), 25.4, 254.0) - l = Line((2.54, 25.4), (254.0, 2540.0), r) + r = Rectangle((0, 0), 25.4, 254.0, units='metric') + l = Line((2.54, 25.4), (254.0, 2540.0), r, units='metric') l.to_inch() assert_equal(l.start, (0.1, 1.0)) assert_equal(l.end, (10.0, 100.0)) assert_equal(l.aperture.width, 1.0) assert_equal(l.aperture.height, 10.0) - r = Rectangle((0, 0), 1.0, 10.0) - l = Line((0.1, 1.0), (10.0, 100.0), r) + r = Rectangle((0, 0), 1.0, 10.0, units='inch') + l = Line((0.1, 1.0), (10.0, 100.0), r, units='inch') l.to_metric() assert_equal(l.start, (2.54, 25.4)) assert_equal(l.end, (254.0, 2540.0)) @@ -151,16 +178,16 @@ def test_arc_bounds(): assert_equal(a.bounding_box, bounds) def test_arc_conversion(): - c = Circle((0, 0), 25.4) - a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0),'clockwise', c) + c = Circle((0, 0), 25.4, units='metric') + a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0),'clockwise', c, units='metric') a.to_inch() assert_equal(a.start, (0.1, 1.0)) assert_equal(a.end, (10.0, 100.0)) assert_equal(a.center, (1000.0, 10000.0)) assert_equal(a.aperture.diameter, 1.0) - c = Circle((0, 0), 1.0) - a = Arc((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0),'clockwise', c) + c = Circle((0, 0), 1.0, units='inch') + a = Arc((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0),'clockwise', c, units='inch') a.to_metric() assert_equal(a.start, (2.54, 25.4)) assert_equal(a.end, (254.0, 2540.0)) @@ -192,11 +219,15 @@ def test_circle_bounds(): assert_equal(c.bounding_box, ((0, 2), (0, 2))) def test_circle_conversion(): - c = Circle((2.54, 25.4), 254.0) + c = Circle((2.54, 25.4), 254.0, units='metric') + c.to_metric() #shouldn't do antyhing c.to_inch() + c.to_inch() #shouldn't do anything assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) - c = Circle((0.1, 1.0), 10.0) + c = Circle((0.1, 1.0), 10.0, units='inch') + c.to_inch() + c.to_metric() c.to_metric() assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) @@ -229,13 +260,17 @@ def test_ellipse_bounds(): assert_equal(e.bounding_box, ((1, 3), (0, 4))) def test_ellipse_conversion(): - e = Ellipse((2.54, 25.4), 254.0, 2540.) + e = Ellipse((2.54, 25.4), 254.0, 2540., units='metric') + e.to_metric() + e.to_inch() e.to_inch() assert_equal(e.position, (0.1, 1.)) assert_equal(e.width, 10.) assert_equal(e.height, 100.) - e = Ellipse((0.1, 1.), 10.0, 100.) + e = Ellipse((0.1, 1.), 10.0, 100., units='inch') + e.to_inch() + e.to_metric() e.to_metric() assert_equal(e.position, (2.54, 25.4)) assert_equal(e.width, 254.) @@ -271,12 +306,16 @@ def test_rectangle_bounds(): assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) def test_rectangle_conversion(): - r = Rectangle((2.54, 25.4), 254.0, 2540.0) + r = Rectangle((2.54, 25.4), 254.0, 2540.0, units='metric') + r.to_metric() + r.to_inch() r.to_inch() assert_equal(r.position, (0.1, 1.0)) assert_equal(r.width, 10.0) assert_equal(r.height, 100.0) - r = Rectangle((0.1, 1.0), 10.0, 100.0) + r = Rectangle((0.1, 1.0), 10.0, 100.0, units='inch') + r.to_inch() + r.to_metric() r.to_metric() assert_equal(r.position, (2.54,25.4)) assert_equal(r.width, 254.0) @@ -312,13 +351,13 @@ def test_diamond_bounds(): assert_array_almost_equal(ybounds, (-1, 1)) def test_diamond_conversion(): - d = Diamond((2.54, 25.4), 254.0, 2540.0) + d = Diamond((2.54, 25.4), 254.0, 2540.0, units='metric') d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.width, 10.0) assert_equal(d.height, 100.0) - d = Diamond((0.1, 1.0), 10.0, 100.0) + d = Diamond((0.1, 1.0), 10.0, 100.0, units='inch') d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.width, 254.0) @@ -358,14 +397,14 @@ def test_chamfer_rectangle_bounds(): assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) def test_chamfer_rectangle_conversion(): - r = ChamferRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False)) + r = ChamferRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False), units='metric') r.to_inch() assert_equal(r.position, (0.1, 1.0)) assert_equal(r.width, 10.0) assert_equal(r.height, 100.0) assert_equal(r.chamfer, 0.01) - r = ChamferRectangle((0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False)) + r = ChamferRectangle((0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False), units='inch') r.to_metric() assert_equal(r.position, (2.54,25.4)) assert_equal(r.width, 254.0) @@ -406,14 +445,14 @@ def test_round_rectangle_bounds(): assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) def test_round_rectangle_conversion(): - r = RoundRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False)) + r = RoundRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False), units='metric') r.to_inch() assert_equal(r.position, (0.1, 1.0)) assert_equal(r.width, 10.0) assert_equal(r.height, 100.0) assert_equal(r.radius, 0.01) - r = RoundRectangle((0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False)) + r = RoundRectangle((0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False), units='inch') r.to_metric() assert_equal(r.position, (2.54,25.4)) assert_equal(r.width, 254.0) @@ -470,13 +509,13 @@ def test_obround_subshapes(): assert_array_almost_equal(ss['circle2'].position, (-1.5, 0)) def test_obround_conversion(): - o = Obround((2.54,25.4), 254.0, 2540.0) + o = Obround((2.54,25.4), 254.0, 2540.0, units='metric') o.to_inch() assert_equal(o.position, (0.1, 1.0)) assert_equal(o.width, 10.0) assert_equal(o.height, 100.0) - o= Obround((0.1, 1.0), 10.0, 100.0) + o= Obround((0.1, 1.0), 10.0, 100.0, units='inch') o.to_metric() assert_equal(o.position, (2.54, 25.4)) assert_equal(o.width, 254.0) @@ -514,12 +553,12 @@ def test_polygon_bounds(): assert_array_almost_equal(ybounds, (-2, 6)) def test_polygon_conversion(): - p = Polygon((2.54, 25.4), 3, 254.0) + p = Polygon((2.54, 25.4), 3, 254.0, units='metric') p.to_inch() assert_equal(p.position, (0.1, 1.0)) assert_equal(p.radius, 10.0) - p = Polygon((0.1, 1.0), 3, 10.0) + p = Polygon((0.1, 1.0), 3, 10.0, units='inch') p.to_metric() assert_equal(p.position, (2.54, 25.4)) assert_equal(p.radius, 254.0) @@ -550,12 +589,12 @@ def test_region_bounds(): def test_region_conversion(): points = ((2.54, 25.4), (254.0,2540.0), (25400.0,254000.0), (2.54,25.4)) - r = Region(points) + r = Region(points, units='metric') r.to_inch() assert_equal(set(r.points), {(0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0)}) points = ((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0), (0.1, 1.0)) - r = Region(points) + r = Region(points, units='inch') r.to_metric() assert_equal(set(r.points), {(2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0)}) @@ -584,12 +623,12 @@ def test_round_butterfly_ctor_validation(): assert_raises(TypeError, RoundButterfly, (3,4,5), 5) def test_round_butterfly_conversion(): - b = RoundButterfly((2.54, 25.4), 254.0) + b = RoundButterfly((2.54, 25.4), 254.0, units='metric') b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.diameter, 10.0) - b = RoundButterfly((0.1, 1.0), 10.0) + b = RoundButterfly((0.1, 1.0), 10.0, units='inch') b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.diameter, (254.0)) @@ -633,12 +672,12 @@ def test_square_butterfly_bounds(): assert_array_almost_equal(ybounds, (-1, 1)) def test_squarebutterfly_conversion(): - b = SquareButterfly((2.54, 25.4), 254.0) + b = SquareButterfly((2.54, 25.4), 254.0, units='metric') b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.side, 10.0) - b = SquareButterfly((0.1, 1.0), 10.0) + b = SquareButterfly((0.1, 1.0), 10.0, units='inch') b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.side, (254.0)) @@ -677,13 +716,13 @@ def test_donut_bounds(): assert_equal(ybounds, (-1., 1.)) def test_donut_conversion(): - d = Donut((2.54, 25.4), 'round', 254.0, 2540.0) + d = Donut((2.54, 25.4), 'round', 254.0, 2540.0, units='metric') d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.inner_diameter, 10.0) assert_equal(d.outer_diameter, 100.0) - d = Donut((0.1, 1.0), 'round', 10.0, 100.0) + d = Donut((0.1, 1.0), 'round', 10.0, 100.0, units='inch') d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.inner_diameter, 254.0) @@ -723,12 +762,12 @@ def test_drill_bounds(): assert_array_almost_equal(ybounds, (1, 3)) def test_drill_conversion(): - d = Drill((2.54, 25.4), 254.) + d = Drill((2.54, 25.4), 254., units='metric') d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.diameter, 10.0) - d = Drill((0.1, 1.0), 10.) + d = Drill((0.1, 1.0), 10., units='inch') d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.diameter, 254.0) -- cgit From e34e1078b67f43be9b678a67cf30d3c53fdea171 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 26 Apr 2015 02:58:12 -0400 Subject: Refactor primitive unit conversion and add regression coverage to tests --- gerber/tests/test_primitives.py | 334 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 310 insertions(+), 24 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index c438735..67c7822 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -77,18 +77,18 @@ def test_line_vertices(): def test_line_conversion(): c = Circle((0, 0), 25.4, units='metric') l = Line((2.54, 25.4), (254.0, 2540.0), c, units='metric') - + # No effect l.to_metric() assert_equal(l.start, (2.54, 25.4)) assert_equal(l.end, (254.0, 2540.0)) assert_equal(l.aperture.diameter, 25.4) - + l.to_inch() assert_equal(l.start, (0.1, 1.0)) assert_equal(l.end, (10.0, 100.0)) assert_equal(l.aperture.diameter, 1.0) - + # No effect l.to_inch() assert_equal(l.start, (0.1, 1.0)) @@ -97,19 +97,19 @@ def test_line_conversion(): c = Circle((0, 0), 1.0, units='inch') l = Line((0.1, 1.0), (10.0, 100.0), c, units='inch') - + # No effect l.to_inch() assert_equal(l.start, (0.1, 1.0)) assert_equal(l.end, (10.0, 100.0)) assert_equal(l.aperture.diameter, 1.0) - - + + l.to_metric() assert_equal(l.start, (2.54, 25.4)) assert_equal(l.end, (254.0, 2540.0)) assert_equal(l.aperture.diameter, 25.4) - + #No effect l.to_metric() assert_equal(l.start, (2.54, 25.4)) @@ -180,6 +180,21 @@ def test_arc_bounds(): def test_arc_conversion(): c = Circle((0, 0), 25.4, units='metric') a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0),'clockwise', c, units='metric') + + #No effect + a.to_metric() + assert_equal(a.start, (2.54, 25.4)) + assert_equal(a.end, (254.0, 2540.0)) + assert_equal(a.center, (25400.0, 254000.0)) + assert_equal(a.aperture.diameter, 25.4) + + a.to_inch() + assert_equal(a.start, (0.1, 1.0)) + assert_equal(a.end, (10.0, 100.0)) + assert_equal(a.center, (1000.0, 10000.0)) + assert_equal(a.aperture.diameter, 1.0) + + #no effect a.to_inch() assert_equal(a.start, (0.1, 1.0)) assert_equal(a.end, (10.0, 100.0)) @@ -220,14 +235,31 @@ def test_circle_bounds(): def test_circle_conversion(): c = Circle((2.54, 25.4), 254.0, units='metric') + c.to_metric() #shouldn't do antyhing + assert_equal(c.position, (2.54, 25.4)) + assert_equal(c.diameter, 254.) + + c.to_inch() + assert_equal(c.position, (0.1, 1.)) + assert_equal(c.diameter, 10.) + + #no effect c.to_inch() - c.to_inch() #shouldn't do anything assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) + c = Circle((0.1, 1.0), 10.0, units='inch') + #No effect c.to_inch() + assert_equal(c.position, (0.1, 1.)) + assert_equal(c.diameter, 10.) + c.to_metric() + assert_equal(c.position, (2.54, 25.4)) + assert_equal(c.diameter, 254.) + + #no effect c.to_metric() assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) @@ -261,16 +293,38 @@ def test_ellipse_bounds(): def test_ellipse_conversion(): e = Ellipse((2.54, 25.4), 254.0, 2540., units='metric') + + #No effect e.to_metric() + assert_equal(e.position, (2.54, 25.4)) + assert_equal(e.width, 254.) + assert_equal(e.height, 2540.) + e.to_inch() + assert_equal(e.position, (0.1, 1.)) + assert_equal(e.width, 10.) + assert_equal(e.height, 100.) + + #No effect e.to_inch() assert_equal(e.position, (0.1, 1.)) assert_equal(e.width, 10.) assert_equal(e.height, 100.) e = Ellipse((0.1, 1.), 10.0, 100., units='inch') + + #no effect e.to_inch() + assert_equal(e.position, (0.1, 1.)) + assert_equal(e.width, 10.) + assert_equal(e.height, 100.) + e.to_metric() + assert_equal(e.position, (2.54, 25.4)) + assert_equal(e.width, 254.) + assert_equal(e.height, 2540.) + + # No effect e.to_metric() assert_equal(e.position, (2.54, 25.4)) assert_equal(e.width, 254.) @@ -307,15 +361,33 @@ def test_rectangle_bounds(): def test_rectangle_conversion(): r = Rectangle((2.54, 25.4), 254.0, 2540.0, units='metric') + r.to_metric() + assert_equal(r.position, (2.54,25.4)) + assert_equal(r.width, 254.0) + assert_equal(r.height, 2540.0) + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + assert_equal(r.height, 100.0) + r.to_inch() assert_equal(r.position, (0.1, 1.0)) assert_equal(r.width, 10.0) assert_equal(r.height, 100.0) + r = Rectangle((0.1, 1.0), 10.0, 100.0, units='inch') r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + assert_equal(r.height, 100.0) + r.to_metric() + assert_equal(r.position, (2.54,25.4)) + assert_equal(r.width, 254.0) + assert_equal(r.height, 2540.0) + r.to_metric() assert_equal(r.position, (2.54,25.4)) assert_equal(r.width, 254.0) @@ -352,12 +424,34 @@ def test_diamond_bounds(): def test_diamond_conversion(): d = Diamond((2.54, 25.4), 254.0, 2540.0, units='metric') + + d.to_metric() + assert_equal(d.position, (2.54, 25.4)) + assert_equal(d.width, 254.0) + assert_equal(d.height, 2540.0) + + d.to_inch() + assert_equal(d.position, (0.1, 1.0)) + assert_equal(d.width, 10.0) + assert_equal(d.height, 100.0) + d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.width, 10.0) assert_equal(d.height, 100.0) d = Diamond((0.1, 1.0), 10.0, 100.0, units='inch') + + d.to_inch() + assert_equal(d.position, (0.1, 1.0)) + assert_equal(d.width, 10.0) + assert_equal(d.height, 100.0) + + d.to_metric() + assert_equal(d.position, (2.54, 25.4)) + assert_equal(d.width, 254.0) + assert_equal(d.height, 2540.0) + d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.width, 254.0) @@ -398,6 +492,19 @@ def test_chamfer_rectangle_bounds(): def test_chamfer_rectangle_conversion(): r = ChamferRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False), units='metric') + + r.to_metric() + assert_equal(r.position, (2.54,25.4)) + assert_equal(r.width, 254.0) + assert_equal(r.height, 2540.0) + assert_equal(r.chamfer, 0.254) + + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + assert_equal(r.height, 100.0) + assert_equal(r.chamfer, 0.01) + r.to_inch() assert_equal(r.position, (0.1, 1.0)) assert_equal(r.width, 10.0) @@ -405,6 +512,18 @@ def test_chamfer_rectangle_conversion(): assert_equal(r.chamfer, 0.01) r = ChamferRectangle((0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False), units='inch') + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + assert_equal(r.height, 100.0) + assert_equal(r.chamfer, 0.01) + + r.to_metric() + assert_equal(r.position, (2.54,25.4)) + assert_equal(r.width, 254.0) + assert_equal(r.height, 2540.0) + assert_equal(r.chamfer, 0.254) + r.to_metric() assert_equal(r.position, (2.54,25.4)) assert_equal(r.width, 254.0) @@ -446,6 +565,19 @@ def test_round_rectangle_bounds(): def test_round_rectangle_conversion(): r = RoundRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False), units='metric') + + r.to_metric() + assert_equal(r.position, (2.54,25.4)) + assert_equal(r.width, 254.0) + assert_equal(r.height, 2540.0) + assert_equal(r.radius, 0.254) + + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + assert_equal(r.height, 100.0) + assert_equal(r.radius, 0.01) + r.to_inch() assert_equal(r.position, (0.1, 1.0)) assert_equal(r.width, 10.0) @@ -453,6 +585,19 @@ def test_round_rectangle_conversion(): assert_equal(r.radius, 0.01) r = RoundRectangle((0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False), units='inch') + + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + assert_equal(r.height, 100.0) + assert_equal(r.radius, 0.01) + + r.to_metric() + assert_equal(r.position, (2.54,25.4)) + assert_equal(r.width, 254.0) + assert_equal(r.height, 2540.0) + assert_equal(r.radius, 0.254) + r.to_metric() assert_equal(r.position, (2.54,25.4)) assert_equal(r.width, 254.0) @@ -510,12 +655,38 @@ def test_obround_subshapes(): def test_obround_conversion(): o = Obround((2.54,25.4), 254.0, 2540.0, units='metric') + + #No effect + o.to_metric() + assert_equal(o.position, (2.54, 25.4)) + assert_equal(o.width, 254.0) + assert_equal(o.height, 2540.0) + + o.to_inch() + assert_equal(o.position, (0.1, 1.0)) + assert_equal(o.width, 10.0) + assert_equal(o.height, 100.0) + + #No effect o.to_inch() assert_equal(o.position, (0.1, 1.0)) assert_equal(o.width, 10.0) assert_equal(o.height, 100.0) o= Obround((0.1, 1.0), 10.0, 100.0, units='inch') + + #No effect + o.to_inch() + assert_equal(o.position, (0.1, 1.0)) + assert_equal(o.width, 10.0) + assert_equal(o.height, 100.0) + + o.to_metric() + assert_equal(o.position, (2.54, 25.4)) + assert_equal(o.width, 254.0) + assert_equal(o.height, 2540.0) + + #No effect o.to_metric() assert_equal(o.position, (2.54, 25.4)) assert_equal(o.width, 254.0) @@ -554,11 +725,33 @@ def test_polygon_bounds(): def test_polygon_conversion(): p = Polygon((2.54, 25.4), 3, 254.0, units='metric') + + #No effect + p.to_metric() + assert_equal(p.position, (2.54, 25.4)) + assert_equal(p.radius, 254.0) + + p.to_inch() + assert_equal(p.position, (0.1, 1.0)) + assert_equal(p.radius, 10.0) + + #No effect p.to_inch() assert_equal(p.position, (0.1, 1.0)) assert_equal(p.radius, 10.0) p = Polygon((0.1, 1.0), 3, 10.0, units='inch') + + #No effect + p.to_inch() + assert_equal(p.position, (0.1, 1.0)) + assert_equal(p.radius, 10.0) + + p.to_metric() + assert_equal(p.position, (2.54, 25.4)) + assert_equal(p.radius, 254.0) + + #No effect p.to_metric() assert_equal(p.position, (2.54, 25.4)) assert_equal(p.radius, 254.0) @@ -623,15 +816,37 @@ def test_round_butterfly_ctor_validation(): assert_raises(TypeError, RoundButterfly, (3,4,5), 5) def test_round_butterfly_conversion(): - b = RoundButterfly((2.54, 25.4), 254.0, units='metric') - b.to_inch() - assert_equal(b.position, (0.1, 1.0)) - assert_equal(b.diameter, 10.0) + b = RoundButterfly((2.54, 25.4), 254.0, units='metric') + + #No Effect + b.to_metric() + assert_equal(b.position, (2.54, 25.4)) + assert_equal(b.diameter, (254.0)) + + b.to_inch() + assert_equal(b.position, (0.1, 1.0)) + assert_equal(b.diameter, 10.0) + + #No effect + b.to_inch() + assert_equal(b.position, (0.1, 1.0)) + assert_equal(b.diameter, 10.0) - b = RoundButterfly((0.1, 1.0), 10.0, units='inch') - b.to_metric() - assert_equal(b.position, (2.54, 25.4)) - assert_equal(b.diameter, (254.0)) + b = RoundButterfly((0.1, 1.0), 10.0, units='inch') + + #No effect + b.to_inch() + assert_equal(b.position, (0.1, 1.0)) + assert_equal(b.diameter, 10.0) + + b.to_metric() + assert_equal(b.position, (2.54, 25.4)) + assert_equal(b.diameter, (254.0)) + + #No Effect + b.to_metric() + assert_equal(b.position, (2.54, 25.4)) + assert_equal(b.diameter, (254.0)) def test_round_butterfly_offset(): b = RoundButterfly((0, 0), 1) @@ -672,15 +887,37 @@ def test_square_butterfly_bounds(): assert_array_almost_equal(ybounds, (-1, 1)) def test_squarebutterfly_conversion(): - b = SquareButterfly((2.54, 25.4), 254.0, units='metric') - b.to_inch() - assert_equal(b.position, (0.1, 1.0)) - assert_equal(b.side, 10.0) + b = SquareButterfly((2.54, 25.4), 254.0, units='metric') + + #No effect + b.to_metric() + assert_equal(b.position, (2.54, 25.4)) + assert_equal(b.side, (254.0)) + + b.to_inch() + assert_equal(b.position, (0.1, 1.0)) + assert_equal(b.side, 10.0) + + #No effect + b.to_inch() + assert_equal(b.position, (0.1, 1.0)) + assert_equal(b.side, 10.0) - b = SquareButterfly((0.1, 1.0), 10.0, units='inch') - b.to_metric() - assert_equal(b.position, (2.54, 25.4)) - assert_equal(b.side, (254.0)) + b = SquareButterfly((0.1, 1.0), 10.0, units='inch') + + #No effect + b.to_inch() + assert_equal(b.position, (0.1, 1.0)) + assert_equal(b.side, 10.0) + + b.to_metric() + assert_equal(b.position, (2.54, 25.4)) + assert_equal(b.side, (254.0)) + + #No effect + b.to_metric() + assert_equal(b.position, (2.54, 25.4)) + assert_equal(b.side, (254.0)) def test_square_butterfly_offset(): b = SquareButterfly((0, 0), 1) @@ -717,12 +954,38 @@ def test_donut_bounds(): def test_donut_conversion(): d = Donut((2.54, 25.4), 'round', 254.0, 2540.0, units='metric') + + #No effect + d.to_metric() + assert_equal(d.position, (2.54, 25.4)) + assert_equal(d.inner_diameter, 254.0) + assert_equal(d.outer_diameter, 2540.0) + + d.to_inch() + assert_equal(d.position, (0.1, 1.0)) + assert_equal(d.inner_diameter, 10.0) + assert_equal(d.outer_diameter, 100.0) + + #No effect d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.inner_diameter, 10.0) assert_equal(d.outer_diameter, 100.0) d = Donut((0.1, 1.0), 'round', 10.0, 100.0, units='inch') + + #No effect + d.to_inch() + assert_equal(d.position, (0.1, 1.0)) + assert_equal(d.inner_diameter, 10.0) + assert_equal(d.outer_diameter, 100.0) + + d.to_metric() + assert_equal(d.position, (2.54, 25.4)) + assert_equal(d.inner_diameter, 254.0) + assert_equal(d.outer_diameter, 2540.0) + + #No effect d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.inner_diameter, 254.0) @@ -763,11 +1026,34 @@ def test_drill_bounds(): def test_drill_conversion(): d = Drill((2.54, 25.4), 254., units='metric') + + #No effect + d.to_metric() + assert_equal(d.position, (2.54, 25.4)) + assert_equal(d.diameter, 254.0) + d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.diameter, 10.0) + + #No effect + d.to_inch() + assert_equal(d.position, (0.1, 1.0)) + assert_equal(d.diameter, 10.0) + d = Drill((0.1, 1.0), 10., units='inch') + + #No effect + d.to_inch() + assert_equal(d.position, (0.1, 1.0)) + assert_equal(d.diameter, 10.0) + + d.to_metric() + assert_equal(d.position, (2.54, 25.4)) + assert_equal(d.diameter, 254.0) + + #No effect d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.diameter, 254.0) -- cgit From cb2fa34e881a389cf8a4bc98fd12be662ff687f8 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 9 Aug 2015 15:11:13 -0400 Subject: Add support for arcs in regions. This fixes the circular cutout issue described in #32. Regions were previously stored as a collection of points, now they are stored as a collection of line and arc primitives. --- gerber/tests/test_primitives.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index 67c7822..f8a32da 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -4,6 +4,7 @@ # Author: Hamilton Kibbe from ..primitives import * from .tests import * +from operator import add def test_primitive_smoketest(): @@ -766,38 +767,31 @@ def test_polygon_offset(): def test_region_ctor(): """ Test Region creation """ + apt = Circle((0,0), 0) + lines = (Line((0,0), (1,0), apt), Line((1,0), (1,1), apt), Line((1,1), (0,1), apt), Line((0,1), (0,0), apt)) points = ((0, 0), (1,0), (1,1), (0,1)) - r = Region(points) - for i, point in enumerate(points): - assert_array_almost_equal(r.points[i], point) + r = Region(lines) + for i, p in enumerate(lines): + assert_equal(r.primitives[i], p) def test_region_bounds(): """ Test region bounding box calculation """ - points = ((0, 0), (1,0), (1,1), (0,1)) - r = Region(points) + apt = Circle((0,0), 0) + lines = (Line((0,0), (1,0), apt), Line((1,0), (1,1), apt), Line((1,1), (0,1), apt), Line((0,1), (0,0), apt)) + r = Region(lines) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (0, 1)) assert_array_almost_equal(ybounds, (0, 1)) -def test_region_conversion(): - points = ((2.54, 25.4), (254.0,2540.0), (25400.0,254000.0), (2.54,25.4)) - r = Region(points, units='metric') - r.to_inch() - assert_equal(set(r.points), {(0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0)}) - - points = ((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0), (0.1, 1.0)) - r = Region(points, units='inch') - r.to_metric() - assert_equal(set(r.points), {(2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0)}) def test_region_offset(): - points = ((0, 0), (1,0), (1,1), (0,1)) - r = Region(points) - r.offset(1, 0) - assert_equal(set(r.points), {(1, 0), (2, 0), (2,1), (1, 1)}) + apt = Circle((0,0), 0) + lines = (Line((0,0), (1,0), apt), Line((1,0), (1,1), apt), Line((1,1), (0,1), apt), Line((0,1), (0,0), apt)) + r = Region(lines) + xlim, ylim = r.bounding_box r.offset(0, 1) - assert_equal(set(r.points), {(1, 1), (2, 1), (2,2), (1, 2)}) + assert_array_almost_equal((xlim, tuple([y+1 for y in ylim])), r.bounding_box) def test_round_butterfly_ctor(): """ Test round butterfly creation -- cgit From 52c6d4928a1b5fc65b95cf5b0784a560cec2ca1d Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sat, 16 Jul 2016 15:49:48 +0800 Subject: Fix most broken tests so that I can safely merge into changes with known expected test result --- gerber/tests/test_primitives.py | 55 +++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index f8a32da..0f13a80 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -150,7 +150,7 @@ def test_arc_radius(): ((0, 1), (1, 0), (0, 0), 1),] for start, end, center, radius in cases: - a = Arc(start, end, center, 'clockwise', 0) + a = Arc(start, end, center, 'clockwise', 0, 'single-quadrant') assert_equal(a.radius, radius) def test_arc_sweep_angle(): @@ -163,7 +163,7 @@ def test_arc_sweep_angle(): for start, end, center, direction, sweep in cases: c = Circle((0,0), 1) - a = Arc(start, end, center, direction, c) + a = Arc(start, end, center, direction, c, 'single-quadrant') assert_equal(a.sweep_angle, sweep) def test_arc_bounds(): @@ -175,12 +175,12 @@ def test_arc_bounds(): ] for start, end, center, direction, bounds in cases: c = Circle((0,0), 1) - a = Arc(start, end, center, direction, c) + a = Arc(start, end, center, direction, c, 'single-quadrant') assert_equal(a.bounding_box, bounds) def test_arc_conversion(): c = Circle((0, 0), 25.4, units='metric') - a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0),'clockwise', c, units='metric') + a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0),'clockwise', c, 'single-quadrant', units='metric') #No effect a.to_metric() @@ -203,7 +203,7 @@ def test_arc_conversion(): assert_equal(a.aperture.diameter, 1.0) c = Circle((0, 0), 1.0, units='inch') - a = Arc((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0),'clockwise', c, units='inch') + a = Arc((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0),'clockwise', c, 'single-quadrant', units='inch') a.to_metric() assert_equal(a.start, (2.54, 25.4)) assert_equal(a.end, (254.0, 2540.0)) @@ -212,7 +212,7 @@ def test_arc_conversion(): def test_arc_offset(): c = Circle((0, 0), 1) - a = Arc((0, 0), (1, 1), (2, 2), 'clockwise', c) + a = Arc((0, 0), (1, 1), (2, 2), 'clockwise', c, 'single-quadrant') a.offset(1, 0) assert_equal(a.start,(1., 0.)) assert_equal(a.end, (2., 1.)) @@ -703,29 +703,30 @@ def test_obround_offset(): def test_polygon_ctor(): """ Test polygon creation """ - test_cases = (((0,0), 3, 5), - ((0, 0), 5, 6), - ((1,1), 7, 7)) - for pos, sides, radius in test_cases: - p = Polygon(pos, sides, radius) + test_cases = (((0,0), 3, 5, 0), + ((0, 0), 5, 6, 0), + ((1,1), 7, 7, 45)) + for pos, sides, radius, hole_radius in test_cases: + p = Polygon(pos, sides, radius, hole_radius) assert_equal(p.position, pos) assert_equal(p.sides, sides) assert_equal(p.radius, radius) + assert_equal(p.hole_radius, hole_radius) def test_polygon_bounds(): """ Test polygon bounding box calculation """ - p = Polygon((2,2), 3, 2) + p = Polygon((2,2), 3, 2, 0) xbounds, ybounds = p.bounding_box assert_array_almost_equal(xbounds, (0, 4)) assert_array_almost_equal(ybounds, (0, 4)) - p = Polygon((2,2),3, 4) + p = Polygon((2,2), 3, 4, 0) xbounds, ybounds = p.bounding_box assert_array_almost_equal(xbounds, (-2, 6)) assert_array_almost_equal(ybounds, (-2, 6)) def test_polygon_conversion(): - p = Polygon((2.54, 25.4), 3, 254.0, units='metric') + p = Polygon((2.54, 25.4), 3, 254.0, 0, units='metric') #No effect p.to_metric() @@ -741,7 +742,7 @@ def test_polygon_conversion(): assert_equal(p.position, (0.1, 1.0)) assert_equal(p.radius, 10.0) - p = Polygon((0.1, 1.0), 3, 10.0, units='inch') + p = Polygon((0.1, 1.0), 3, 10.0, 0, units='inch') #No effect p.to_inch() @@ -758,7 +759,7 @@ def test_polygon_conversion(): assert_equal(p.radius, 254.0) def test_polygon_offset(): - p = Polygon((0, 0), 5, 10) + p = Polygon((0, 0), 5, 10, 0) p.offset(1, 0) assert_equal(p.position,(1., 0.)) p.offset(0, 1) @@ -997,7 +998,7 @@ def test_drill_ctor(): """ test_cases = (((0, 0), 2), ((1, 1), 3), ((2, 2), 5)) for position, diameter in test_cases: - d = Drill(position, diameter) + d = Drill(position, diameter, None) assert_equal(d.position, position) assert_equal(d.diameter, diameter) assert_equal(d.radius, diameter/2.) @@ -1005,21 +1006,21 @@ def test_drill_ctor(): def test_drill_ctor_validation(): """ Test drill argument validation """ - assert_raises(TypeError, Drill, 3, 5) - assert_raises(TypeError, Drill, (3,4,5), 5) + assert_raises(TypeError, Drill, 3, 5, None) + assert_raises(TypeError, Drill, (3,4,5), 5, None) def test_drill_bounds(): - d = Drill((0, 0), 2) + d = Drill((0, 0), 2, None) xbounds, ybounds = d.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) - d = Drill((1, 2), 2) + d = Drill((1, 2), 2, None) xbounds, ybounds = d.bounding_box assert_array_almost_equal(xbounds, (0, 2)) assert_array_almost_equal(ybounds, (1, 3)) def test_drill_conversion(): - d = Drill((2.54, 25.4), 254., units='metric') + d = Drill((2.54, 25.4), 254., None, units='metric') #No effect d.to_metric() @@ -1036,7 +1037,7 @@ def test_drill_conversion(): assert_equal(d.diameter, 10.0) - d = Drill((0.1, 1.0), 10., units='inch') + d = Drill((0.1, 1.0), 10., None, units='inch') #No effect d.to_inch() @@ -1053,15 +1054,15 @@ def test_drill_conversion(): assert_equal(d.diameter, 254.0) def test_drill_offset(): - d = Drill((0, 0), 1.) + d = Drill((0, 0), 1., None) d.offset(1, 0) assert_equal(d.position,(1., 0.)) d.offset(0, 1) assert_equal(d.position,(1., 1.)) def test_drill_equality(): - d = Drill((2.54, 25.4), 254.) - d1 = Drill((2.54, 25.4), 254.) + d = Drill((2.54, 25.4), 254., None) + d1 = Drill((2.54, 25.4), 254., None) assert_equal(d, d1) - d1 = Drill((2.54, 25.4), 254.2) + d1 = Drill((2.54, 25.4), 254.2, None) assert_not_equal(d, d1) -- cgit From f0585baefa54c5cd891ba04c81053956b1a59977 Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sun, 17 Jul 2016 13:14:54 +0800 Subject: Create first test that renders and validates the the rendered PNG is correct. --- gerber/tests/test_primitives.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index 0f13a80..a88497c 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -9,10 +9,18 @@ from operator import add def test_primitive_smoketest(): p = Primitive() - assert_raises(NotImplementedError, p.bounding_box) + try: + p.bounding_box + assert_false(True, 'should have thrown the exception') + except NotImplementedError: + pass p.to_metric() p.to_inch() - p.offset(1, 1) + try: + p.offset(1, 1) + assert_false(True, 'should have thrown the exception') + except NotImplementedError: + pass def test_line_angle(): """ Test Line primitive angle calculation -- cgit From 7cd6acf12670f3773113f67ed2acb35cb21c32a0 Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sun, 24 Jul 2016 17:08:47 +0800 Subject: Add many render tests based on the Umaco gerger specification. Fix multiple rendering bugs, especially related to holes in flashed apertures --- gerber/tests/test_primitives.py | 106 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index a88497c..bc67891 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -236,6 +236,12 @@ def test_circle_radius(): c = Circle((1, 1), 2) assert_equal(c.radius, 1) +def test_circle_hole_radius(): + """ Test Circle primitive hole radius calculation + """ + c = Circle((1, 1), 4, 2) + assert_equal(c.hole_radius, 1) + def test_circle_bounds(): """ Test Circle bounding box calculation """ @@ -243,35 +249,81 @@ def test_circle_bounds(): assert_equal(c.bounding_box, ((0, 2), (0, 2))) def test_circle_conversion(): + """Circle conversion of units""" + # Circle initially metric, no hole c = Circle((2.54, 25.4), 254.0, units='metric') c.to_metric() #shouldn't do antyhing assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) + assert_equal(c.hole_diameter, 0.) c.to_inch() assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) + assert_equal(c.hole_diameter, 0) #no effect c.to_inch() assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) + assert_equal(c.hole_diameter, 0) + + # Circle initially metric, with hole + c = Circle((2.54, 25.4), 254.0, 127.0, units='metric') + c.to_metric() #shouldn't do antyhing + assert_equal(c.position, (2.54, 25.4)) + assert_equal(c.diameter, 254.) + assert_equal(c.hole_diameter, 127.) + + c.to_inch() + assert_equal(c.position, (0.1, 1.)) + assert_equal(c.diameter, 10.) + assert_equal(c.hole_diameter, 5.) + + #no effect + c.to_inch() + assert_equal(c.position, (0.1, 1.)) + assert_equal(c.diameter, 10.) + assert_equal(c.hole_diameter, 5.) + + # Circle initially inch, no hole c = Circle((0.1, 1.0), 10.0, units='inch') #No effect c.to_inch() assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) + assert_equal(c.hole_diameter, 0) c.to_metric() assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) + assert_equal(c.hole_diameter, 0) #no effect c.to_metric() assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) + assert_equal(c.hole_diameter, 0) + + c = Circle((0.1, 1.0), 10.0, 5.0, units='inch') + #No effect + c.to_inch() + assert_equal(c.position, (0.1, 1.)) + assert_equal(c.diameter, 10.) + assert_equal(c.hole_diameter, 5.) + + c.to_metric() + assert_equal(c.position, (2.54, 25.4)) + assert_equal(c.diameter, 254.) + assert_equal(c.hole_diameter, 127.) + + #no effect + c.to_metric() + assert_equal(c.position, (2.54, 25.4)) + assert_equal(c.diameter, 254.) + assert_equal(c.hole_diameter, 127.) def test_circle_offset(): c = Circle((0, 0), 1) @@ -355,6 +407,15 @@ def test_rectangle_ctor(): assert_equal(r.position, pos) assert_equal(r.width, width) assert_equal(r.height, height) + +def test_rectangle_hole_radius(): + """ Test rectangle hole diameter calculation + """ + r = Rectangle((0,0), 2, 2) + assert_equal(0, r.hole_radius) + + r = Rectangle((0,0), 2, 2, 1) + assert_equal(0.5, r.hole_radius) def test_rectangle_bounds(): """ Test rectangle bounding box calculation @@ -369,6 +430,9 @@ def test_rectangle_bounds(): assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) def test_rectangle_conversion(): + """Test converting rectangles between units""" + + # Initially metric no hole r = Rectangle((2.54, 25.4), 254.0, 2540.0, units='metric') r.to_metric() @@ -385,7 +449,29 @@ def test_rectangle_conversion(): assert_equal(r.position, (0.1, 1.0)) assert_equal(r.width, 10.0) assert_equal(r.height, 100.0) + + # Initially metric with hole + r = Rectangle((2.54, 25.4), 254.0, 2540.0, 127.0, units='metric') + + r.to_metric() + assert_equal(r.position, (2.54,25.4)) + assert_equal(r.width, 254.0) + assert_equal(r.height, 2540.0) + assert_equal(r.hole_diameter, 127.0) + + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + assert_equal(r.height, 100.0) + assert_equal(r.hole_diameter, 5.0) + + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + assert_equal(r.height, 100.0) + assert_equal(r.hole_diameter, 5.0) + # Initially inch, no hole r = Rectangle((0.1, 1.0), 10.0, 100.0, units='inch') r.to_inch() assert_equal(r.position, (0.1, 1.0)) @@ -401,6 +487,26 @@ def test_rectangle_conversion(): assert_equal(r.position, (2.54,25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) + + # Initially inch with hole + r = Rectangle((0.1, 1.0), 10.0, 100.0, 5.0, units='inch') + r.to_inch() + assert_equal(r.position, (0.1, 1.0)) + assert_equal(r.width, 10.0) + assert_equal(r.height, 100.0) + assert_equal(r.hole_diameter, 5.0) + + r.to_metric() + assert_equal(r.position, (2.54,25.4)) + assert_equal(r.width, 254.0) + assert_equal(r.height, 2540.0) + assert_equal(r.hole_diameter, 127.0) + + r.to_metric() + assert_equal(r.position, (2.54,25.4)) + assert_equal(r.width, 254.0) + assert_equal(r.height, 2540.0) + assert_equal(r.hole_diameter, 127.0) def test_rectangle_offset(): r = Rectangle((0, 0), 1, 2) -- cgit From 965d3ce23b92f8aff1063debd6d3364de15791fe Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sun, 24 Jul 2016 22:08:31 +0800 Subject: Add more tests for rendering to PNG. Start adding tests for rendering to Gerber format. Changed definition of no hole to use None instead of 0 so we can differentiate when writing to Gerber format. Makde polygon use hole diameter instead of hole radius to match other primitives --- gerber/tests/test_primitives.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index bc67891..61cf22d 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -256,18 +256,18 @@ def test_circle_conversion(): c.to_metric() #shouldn't do antyhing assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) - assert_equal(c.hole_diameter, 0.) + assert_equal(c.hole_diameter, None) c.to_inch() assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) - assert_equal(c.hole_diameter, 0) + assert_equal(c.hole_diameter, None) #no effect c.to_inch() assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) - assert_equal(c.hole_diameter, 0) + assert_equal(c.hole_diameter, None) # Circle initially metric, with hole c = Circle((2.54, 25.4), 254.0, 127.0, units='metric') @@ -294,18 +294,18 @@ def test_circle_conversion(): c.to_inch() assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) - assert_equal(c.hole_diameter, 0) + assert_equal(c.hole_diameter, None) c.to_metric() assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) - assert_equal(c.hole_diameter, 0) + assert_equal(c.hole_diameter, None) #no effect c.to_metric() assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) - assert_equal(c.hole_diameter, 0) + assert_equal(c.hole_diameter, None) c = Circle((0.1, 1.0), 10.0, 5.0, units='inch') #No effect @@ -820,12 +820,12 @@ def test_polygon_ctor(): test_cases = (((0,0), 3, 5, 0), ((0, 0), 5, 6, 0), ((1,1), 7, 7, 45)) - for pos, sides, radius, hole_radius in test_cases: - p = Polygon(pos, sides, radius, hole_radius) + for pos, sides, radius, hole_diameter in test_cases: + p = Polygon(pos, sides, radius, hole_diameter) assert_equal(p.position, pos) assert_equal(p.sides, sides) assert_equal(p.radius, radius) - assert_equal(p.hole_radius, hole_radius) + assert_equal(p.hole_diameter, hole_diameter) def test_polygon_bounds(): """ Test polygon bounding box calculation -- cgit From 8cd842a41a55ab3d8f558a2e3e198beba7da58a1 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 21 Jan 2016 03:57:44 -0500 Subject: Manually mere rendering changes --- gerber/tests/test_primitives.py | 416 ++++++++++++++++++++++++---------------- 1 file changed, 249 insertions(+), 167 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index 61cf22d..261e6ef 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -2,18 +2,23 @@ # -*- coding: utf-8 -*- # Author: Hamilton Kibbe +from operator import add + from ..primitives import * from .tests import * -from operator import add def test_primitive_smoketest(): p = Primitive() +<<<<<<< HEAD try: p.bounding_box assert_false(True, 'should have thrown the exception') except NotImplementedError: pass +======= + #assert_raises(NotImplementedError, p.bounding_box) +>>>>>>> 5476da8... Fix a bunch of rendering bugs. p.to_metric() p.to_inch() try: @@ -22,6 +27,7 @@ def test_primitive_smoketest(): except NotImplementedError: pass + def test_line_angle(): """ Test Line primitive angle calculation """ @@ -32,19 +38,20 @@ def test_line_angle(): ((0, 0), (-1, 0), math.radians(180)), ((0, 0), (-1, -1), math.radians(225)), ((0, 0), (0, -1), math.radians(270)), - ((0, 0), (1, -1), math.radians(315)),] + ((0, 0), (1, -1), math.radians(315)), ] for start, end, expected in cases: l = Line(start, end, 0) line_angle = (l.angle + 2 * math.pi) % (2 * math.pi) assert_almost_equal(line_angle, expected) + def test_line_bounds(): """ Test Line primitive bounding box calculation """ cases = [((0, 0), (1, 1), ((-1, 2), (-1, 2))), ((-1, -1), (1, 1), ((-2, 2), (-2, 2))), ((1, 1), (-1, -1), ((-2, 2), (-2, 2))), - ((-1, 1), (1, -1), ((-2, 2), (-2, 2))),] + ((-1, 1), (1, -1), ((-2, 2), (-2, 2))), ] c = Circle((0, 0), 2) r = Rectangle((0, 0), 2, 2) @@ -57,11 +64,12 @@ def test_line_bounds(): cases = [((0, 0), (1, 1), ((-1.5, 2.5), (-1, 2))), ((-1, -1), (1, 1), ((-2.5, 2.5), (-2, 2))), ((1, 1), (-1, -1), ((-2.5, 2.5), (-2, 2))), - ((-1, 1), (1, -1), ((-2.5, 2.5), (-2, 2))),] + ((-1, 1), (1, -1), ((-2.5, 2.5), (-2, 2))), ] for start, end, expected in cases: l = Line(start, end, r) assert_equal(l.bounding_box, expected) + def test_line_vertices(): c = Circle((0, 0), 2) l = Line((0, 0), (1, 1), c) @@ -69,20 +77,25 @@ def test_line_vertices(): # All 4 compass points, all 4 quadrants and the case where start == end test_cases = [((0, 0), (1, 0), ((-1, -1), (-1, 1), (2, 1), (2, -1))), - ((0, 0), (1, 1), ((-1, -1), (-1, 1), (0, 2), (2, 2), (2, 0), (1,-1))), - ((0, 0), (0, 1), ((-1, -1), (-1, 2), (1, 2), (1, -1))), - ((0, 0), (-1, 1), ((-1, -1), (-2, 0), (-2, 2), (0, 2), (1, 1), (1, -1))), - ((0, 0), (-1, 0), ((-2, -1), (-2, 1), (1, 1), (1, -1))), - ((0, 0), (-1, -1), ((-2, -2), (1, -1), (1, 1), (-1, 1), (-2, 0), (0,-2))), - ((0, 0), (0, -1), ((-1, -2), (-1, 1), (1, 1), (1, -2))), - ((0, 0), (1, -1), ((-1, -1), (0, -2), (2, -2), (2, 0), (1, 1), (-1, 1))), - ((0, 0), (0, 0), ((-1, -1), (-1, 1), (1, 1), (1, -1))),] + ((0, 0), (1, 1), ((-1, -1), (-1, 1), + (0, 2), (2, 2), (2, 0), (1, -1))), + ((0, 0), (0, 1), ((-1, -1), (-1, 2), (1, 2), (1, -1))), + ((0, 0), (-1, 1), ((-1, -1), (-2, 0), + (-2, 2), (0, 2), (1, 1), (1, -1))), + ((0, 0), (-1, 0), ((-2, -1), (-2, 1), (1, 1), (1, -1))), + ((0, 0), (-1, -1), ((-2, -2), (1, -1), + (1, 1), (-1, 1), (-2, 0), (0, -2))), + ((0, 0), (0, -1), ((-1, -2), (-1, 1), (1, 1), (1, -2))), + ((0, 0), (1, -1), ((-1, -1), (0, -2), + (2, -2), (2, 0), (1, 1), (-1, 1))), + ((0, 0), (0, 0), ((-1, -1), (-1, 1), (1, 1), (1, -1))), ] r = Rectangle((0, 0), 2, 2) for start, end, vertices in test_cases: l = Line(start, end, r) assert_equal(set(vertices), set(l.vertices)) + def test_line_conversion(): c = Circle((0, 0), 25.4, units='metric') l = Line((2.54, 25.4), (254.0, 2540.0), c, units='metric') @@ -113,13 +126,12 @@ def test_line_conversion(): assert_equal(l.end, (10.0, 100.0)) assert_equal(l.aperture.diameter, 1.0) - l.to_metric() assert_equal(l.start, (2.54, 25.4)) assert_equal(l.end, (254.0, 2540.0)) assert_equal(l.aperture.diameter, 25.4) - #No effect + # No effect l.to_metric() assert_equal(l.start, (2.54, 25.4)) assert_equal(l.end, (254.0, 2540.0)) @@ -141,56 +153,62 @@ def test_line_conversion(): assert_equal(l.aperture.width, 25.4) assert_equal(l.aperture.height, 254.0) + def test_line_offset(): c = Circle((0, 0), 1) l = Line((0, 0), (1, 1), c) l.offset(1, 0) - assert_equal(l.start,(1., 0.)) + assert_equal(l.start, (1., 0.)) assert_equal(l.end, (2., 1.)) l.offset(0, 1) - assert_equal(l.start,(1., 1.)) + assert_equal(l.start, (1., 1.)) assert_equal(l.end, (2., 2.)) + def test_arc_radius(): """ Test Arc primitive radius calculation """ cases = [((-3, 4), (5, 0), (0, 0), 5), - ((0, 1), (1, 0), (0, 0), 1),] + ((0, 1), (1, 0), (0, 0), 1), ] for start, end, center, radius in cases: a = Arc(start, end, center, 'clockwise', 0, 'single-quadrant') assert_equal(a.radius, radius) + def test_arc_sweep_angle(): """ Test Arc primitive sweep angle calculation """ cases = [((1, 0), (0, 1), (0, 0), 'counterclockwise', math.radians(90)), ((1, 0), (0, 1), (0, 0), 'clockwise', math.radians(270)), ((1, 0), (-1, 0), (0, 0), 'clockwise', math.radians(180)), - ((1, 0), (-1, 0), (0, 0), 'counterclockwise', math.radians(180)),] + ((1, 0), (-1, 0), (0, 0), 'counterclockwise', math.radians(180)), ] for start, end, center, direction, sweep in cases: c = Circle((0,0), 1) a = Arc(start, end, center, direction, c, 'single-quadrant') assert_equal(a.sweep_angle, sweep) + def test_arc_bounds(): """ Test Arc primitive bounding box calculation """ - cases = [((1, 0), (0, 1), (0, 0), 'clockwise', ((-1.5, 1.5), (-1.5, 1.5))), - ((1, 0), (0, 1), (0, 0), 'counterclockwise', ((-0.5, 1.5), (-0.5, 1.5))), - #TODO: ADD MORE TEST CASES HERE + cases = [((1, 0), (0, 1), (0, 0), 'clockwise', ((-1.5, 1.5), (-1.5, 1.5))), + ((1, 0), (0, 1), (0, 0), 'counterclockwise', + ((-0.5, 1.5), (-0.5, 1.5))), + # TODO: ADD MORE TEST CASES HERE ] for start, end, center, direction, bounds in cases: c = Circle((0,0), 1) a = Arc(start, end, center, direction, c, 'single-quadrant') assert_equal(a.bounding_box, bounds) + def test_arc_conversion(): c = Circle((0, 0), 25.4, units='metric') a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0),'clockwise', c, 'single-quadrant', units='metric') - #No effect + # No effect a.to_metric() assert_equal(a.start, (2.54, 25.4)) assert_equal(a.end, (254.0, 2540.0)) @@ -203,7 +221,7 @@ def test_arc_conversion(): assert_equal(a.center, (1000.0, 10000.0)) assert_equal(a.aperture.diameter, 1.0) - #no effect + # no effect a.to_inch() assert_equal(a.start, (0.1, 1.0)) assert_equal(a.end, (10.0, 100.0)) @@ -218,18 +236,20 @@ def test_arc_conversion(): assert_equal(a.center, (25400.0, 254000.0)) assert_equal(a.aperture.diameter, 25.4) + def test_arc_offset(): c = Circle((0, 0), 1) a = Arc((0, 0), (1, 1), (2, 2), 'clockwise', c, 'single-quadrant') a.offset(1, 0) - assert_equal(a.start,(1., 0.)) + assert_equal(a.start, (1., 0.)) assert_equal(a.end, (2., 1.)) assert_equal(a.center, (3., 2.)) a.offset(0, 1) - assert_equal(a.start,(1., 1.)) + assert_equal(a.start, (1., 1.)) assert_equal(a.end, (2., 2.)) assert_equal(a.center, (3., 3.)) + def test_circle_radius(): """ Test Circle primitive radius calculation """ @@ -248,12 +268,13 @@ def test_circle_bounds(): c = Circle((1, 1), 2) assert_equal(c.bounding_box, ((0, 2), (0, 2))) + def test_circle_conversion(): """Circle conversion of units""" # Circle initially metric, no hole c = Circle((2.54, 25.4), 254.0, units='metric') - c.to_metric() #shouldn't do antyhing + c.to_metric() # shouldn't do antyhing assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) assert_equal(c.hole_diameter, None) @@ -263,7 +284,7 @@ def test_circle_conversion(): assert_equal(c.diameter, 10.) assert_equal(c.hole_diameter, None) - #no effect + # no effect c.to_inch() assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) @@ -290,7 +311,7 @@ def test_circle_conversion(): # Circle initially inch, no hole c = Circle((0.1, 1.0), 10.0, units='inch') - #No effect + # No effect c.to_inch() assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) @@ -301,7 +322,7 @@ def test_circle_conversion(): assert_equal(c.diameter, 254.) assert_equal(c.hole_diameter, None) - #no effect + # no effect c.to_metric() assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) @@ -325,12 +346,14 @@ def test_circle_conversion(): assert_equal(c.diameter, 254.) assert_equal(c.hole_diameter, 127.) + def test_circle_offset(): c = Circle((0, 0), 1) c.offset(1, 0) - assert_equal(c.position,(1., 0.)) + assert_equal(c.position, (1., 0.)) c.offset(0, 1) - assert_equal(c.position,(1., 1.)) + assert_equal(c.position, (1., 1.)) + def test_ellipse_ctor(): """ Test ellipse creation @@ -340,6 +363,7 @@ def test_ellipse_ctor(): assert_equal(e.width, 3) assert_equal(e.height, 2) + def test_ellipse_bounds(): """ Test ellipse bounding box calculation """ @@ -352,10 +376,11 @@ def test_ellipse_bounds(): e = Ellipse((2, 2), 4, 2, rotation=270) assert_equal(e.bounding_box, ((1, 3), (0, 4))) + def test_ellipse_conversion(): e = Ellipse((2.54, 25.4), 254.0, 2540., units='metric') - #No effect + # No effect e.to_metric() assert_equal(e.position, (2.54, 25.4)) assert_equal(e.width, 254.) @@ -366,7 +391,7 @@ def test_ellipse_conversion(): assert_equal(e.width, 10.) assert_equal(e.height, 100.) - #No effect + # No effect e.to_inch() assert_equal(e.position, (0.1, 1.)) assert_equal(e.width, 10.) @@ -374,7 +399,7 @@ def test_ellipse_conversion(): e = Ellipse((0.1, 1.), 10.0, 100., units='inch') - #no effect + # no effect e.to_inch() assert_equal(e.position, (0.1, 1.)) assert_equal(e.width, 10.) @@ -391,17 +416,19 @@ def test_ellipse_conversion(): assert_equal(e.width, 254.) assert_equal(e.height, 2540.) + def test_ellipse_offset(): e = Ellipse((0, 0), 1, 2) e.offset(1, 0) - assert_equal(e.position,(1., 0.)) + assert_equal(e.position, (1., 0.)) e.offset(0, 1) - assert_equal(e.position,(1., 1.)) + assert_equal(e.position, (1., 1.)) + def test_rectangle_ctor(): """ Test rectangle creation """ - test_cases = (((0,0), 1, 1), ((0, 0), 1, 2), ((1,1), 1, 2)) + test_cases = (((0, 0), 1, 1), ((0, 0), 1, 2), ((1, 1), 1, 2)) for pos, width, height in test_cases: r = Rectangle(pos, width, height) assert_equal(r.position, pos) @@ -417,18 +444,20 @@ def test_rectangle_hole_radius(): r = Rectangle((0,0), 2, 2, 1) assert_equal(0.5, r.hole_radius) + def test_rectangle_bounds(): """ Test rectangle bounding box calculation """ - r = Rectangle((0,0), 2, 2) + r = Rectangle((0, 0), 2, 2) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) - r = Rectangle((0,0), 2, 2, rotation=45) + r = Rectangle((0, 0), 2, 2, rotation=45) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + def test_rectangle_conversion(): """Test converting rectangles between units""" @@ -436,7 +465,7 @@ def test_rectangle_conversion(): r = Rectangle((2.54, 25.4), 254.0, 2540.0, units='metric') r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) @@ -479,12 +508,12 @@ def test_rectangle_conversion(): assert_equal(r.height, 100.0) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) @@ -508,35 +537,39 @@ def test_rectangle_conversion(): assert_equal(r.height, 2540.0) assert_equal(r.hole_diameter, 127.0) + def test_rectangle_offset(): r = Rectangle((0, 0), 1, 2) r.offset(1, 0) - assert_equal(r.position,(1., 0.)) + assert_equal(r.position, (1., 0.)) r.offset(0, 1) - assert_equal(r.position,(1., 1.)) + assert_equal(r.position, (1., 1.)) + def test_diamond_ctor(): """ Test diamond creation """ - test_cases = (((0,0), 1, 1), ((0, 0), 1, 2), ((1,1), 1, 2)) + test_cases = (((0, 0), 1, 1), ((0, 0), 1, 2), ((1, 1), 1, 2)) for pos, width, height in test_cases: d = Diamond(pos, width, height) assert_equal(d.position, pos) assert_equal(d.width, width) assert_equal(d.height, height) + def test_diamond_bounds(): """ Test diamond bounding box calculation """ - d = Diamond((0,0), 2, 2) + d = Diamond((0, 0), 2, 2) xbounds, ybounds = d.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) - d = Diamond((0,0), math.sqrt(2), math.sqrt(2), rotation=45) + d = Diamond((0, 0), math.sqrt(2), math.sqrt(2), rotation=45) xbounds, ybounds = d.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) + def test_diamond_conversion(): d = Diamond((2.54, 25.4), 254.0, 2540.0, units='metric') @@ -572,19 +605,21 @@ def test_diamond_conversion(): assert_equal(d.width, 254.0) assert_equal(d.height, 2540.0) + def test_diamond_offset(): d = Diamond((0, 0), 1, 2) d.offset(1, 0) - assert_equal(d.position,(1., 0.)) + assert_equal(d.position, (1., 0.)) d.offset(0, 1) - assert_equal(d.position,(1., 1.)) + assert_equal(d.position, (1., 1.)) + def test_chamfer_rectangle_ctor(): """ Test chamfer rectangle creation """ - test_cases = (((0,0), 1, 1, 0.2, (True, True, False, False)), + test_cases = (((0, 0), 1, 1, 0.2, (True, True, False, False)), ((0, 0), 1, 2, 0.3, (True, True, True, True)), - ((1,1), 1, 2, 0.4, (False, False, False, False))) + ((1, 1), 1, 2, 0.4, (False, False, False, False))) for pos, width, height, chamfer, corners in test_cases: r = ChamferRectangle(pos, width, height, chamfer, corners) assert_equal(r.position, pos) @@ -593,23 +628,27 @@ def test_chamfer_rectangle_ctor(): assert_equal(r.chamfer, chamfer) assert_array_almost_equal(r.corners, corners) + def test_chamfer_rectangle_bounds(): """ Test chamfer rectangle bounding box calculation """ - r = ChamferRectangle((0,0), 2, 2, 0.2, (True, True, False, False)) + r = ChamferRectangle((0, 0), 2, 2, 0.2, (True, True, False, False)) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) - r = ChamferRectangle((0,0), 2, 2, 0.2, (True, True, False, False), rotation=45) + r = ChamferRectangle( + (0, 0), 2, 2, 0.2, (True, True, False, False), rotation=45) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + def test_chamfer_rectangle_conversion(): - r = ChamferRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False), units='metric') + r = ChamferRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, + (True, True, False, False), units='metric') r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.chamfer, 0.254) @@ -626,7 +665,8 @@ def test_chamfer_rectangle_conversion(): assert_equal(r.height, 100.0) assert_equal(r.chamfer, 0.01) - r = ChamferRectangle((0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False), units='inch') + r = ChamferRectangle((0.1, 1.0), 10.0, 100.0, 0.01, + (True, True, False, False), units='inch') r.to_inch() assert_equal(r.position, (0.1, 1.0)) assert_equal(r.width, 10.0) @@ -634,30 +674,32 @@ def test_chamfer_rectangle_conversion(): assert_equal(r.chamfer, 0.01) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.chamfer, 0.254) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.chamfer, 0.254) + def test_chamfer_rectangle_offset(): r = ChamferRectangle((0, 0), 1, 2, 0.01, (True, True, False, False)) r.offset(1, 0) - assert_equal(r.position,(1., 0.)) + assert_equal(r.position, (1., 0.)) r.offset(0, 1) - assert_equal(r.position,(1., 1.)) + assert_equal(r.position, (1., 1.)) + def test_round_rectangle_ctor(): """ Test round rectangle creation """ - test_cases = (((0,0), 1, 1, 0.2, (True, True, False, False)), + test_cases = (((0, 0), 1, 1, 0.2, (True, True, False, False)), ((0, 0), 1, 2, 0.3, (True, True, True, True)), - ((1,1), 1, 2, 0.4, (False, False, False, False))) + ((1, 1), 1, 2, 0.4, (False, False, False, False))) for pos, width, height, radius, corners in test_cases: r = RoundRectangle(pos, width, height, radius, corners) assert_equal(r.position, pos) @@ -666,23 +708,27 @@ def test_round_rectangle_ctor(): assert_equal(r.radius, radius) assert_array_almost_equal(r.corners, corners) + def test_round_rectangle_bounds(): """ Test round rectangle bounding box calculation """ - r = RoundRectangle((0,0), 2, 2, 0.2, (True, True, False, False)) + r = RoundRectangle((0, 0), 2, 2, 0.2, (True, True, False, False)) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) - r = RoundRectangle((0,0), 2, 2, 0.2, (True, True, False, False), rotation=45) + r = RoundRectangle((0, 0), 2, 2, 0.2, + (True, True, False, False), rotation=45) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (-math.sqrt(2), math.sqrt(2))) assert_array_almost_equal(ybounds, (-math.sqrt(2), math.sqrt(2))) + def test_round_rectangle_conversion(): - r = RoundRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, (True, True, False, False), units='metric') + r = RoundRectangle((2.54, 25.4), 254.0, 2540.0, 0.254, + (True, True, False, False), units='metric') r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.radius, 0.254) @@ -699,7 +745,8 @@ def test_round_rectangle_conversion(): assert_equal(r.height, 100.0) assert_equal(r.radius, 0.01) - r = RoundRectangle((0.1, 1.0), 10.0, 100.0, 0.01, (True, True, False, False), units='inch') + r = RoundRectangle((0.1, 1.0), 10.0, 100.0, 0.01, + (True, True, False, False), units='inch') r.to_inch() assert_equal(r.position, (0.1, 1.0)) @@ -708,70 +755,76 @@ def test_round_rectangle_conversion(): assert_equal(r.radius, 0.01) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.radius, 0.254) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.radius, 0.254) + def test_round_rectangle_offset(): r = RoundRectangle((0, 0), 1, 2, 0.01, (True, True, False, False)) r.offset(1, 0) - assert_equal(r.position,(1., 0.)) + assert_equal(r.position, (1., 0.)) r.offset(0, 1) - assert_equal(r.position,(1., 1.)) + assert_equal(r.position, (1., 1.)) + def test_obround_ctor(): """ Test obround creation """ - test_cases = (((0,0), 1, 1), + test_cases = (((0, 0), 1, 1), ((0, 0), 1, 2), - ((1,1), 1, 2)) + ((1, 1), 1, 2)) for pos, width, height in test_cases: o = Obround(pos, width, height) assert_equal(o.position, pos) assert_equal(o.width, width) assert_equal(o.height, height) + def test_obround_bounds(): """ Test obround bounding box calculation """ - o = Obround((2,2),2,4) + o = Obround((2, 2), 2, 4) xbounds, ybounds = o.bounding_box assert_array_almost_equal(xbounds, (1, 3)) assert_array_almost_equal(ybounds, (0, 4)) - o = Obround((2,2),4,2) + o = Obround((2, 2), 4, 2) xbounds, ybounds = o.bounding_box assert_array_almost_equal(xbounds, (0, 4)) assert_array_almost_equal(ybounds, (1, 3)) + def test_obround_orientation(): o = Obround((0, 0), 2, 1) assert_equal(o.orientation, 'horizontal') o = Obround((0, 0), 1, 2) assert_equal(o.orientation, 'vertical') + def test_obround_subshapes(): - o = Obround((0,0), 1, 4) + o = Obround((0, 0), 1, 4) ss = o.subshapes assert_array_almost_equal(ss['rectangle'].position, (0, 0)) assert_array_almost_equal(ss['circle1'].position, (0, 1.5)) assert_array_almost_equal(ss['circle2'].position, (0, -1.5)) - o = Obround((0,0), 4, 1) + o = Obround((0, 0), 4, 1) ss = o.subshapes assert_array_almost_equal(ss['rectangle'].position, (0, 0)) assert_array_almost_equal(ss['circle1'].position, (1.5, 0)) assert_array_almost_equal(ss['circle2'].position, (-1.5, 0)) + def test_obround_conversion(): - o = Obround((2.54,25.4), 254.0, 2540.0, units='metric') + o = Obround((2.54, 25.4), 254.0, 2540.0, units='metric') - #No effect + # No effect o.to_metric() assert_equal(o.position, (2.54, 25.4)) assert_equal(o.width, 254.0) @@ -782,15 +835,15 @@ def test_obround_conversion(): assert_equal(o.width, 10.0) assert_equal(o.height, 100.0) - #No effect + # No effect o.to_inch() assert_equal(o.position, (0.1, 1.0)) assert_equal(o.width, 10.0) assert_equal(o.height, 100.0) - o= Obround((0.1, 1.0), 10.0, 100.0, units='inch') + o = Obround((0.1, 1.0), 10.0, 100.0, units='inch') - #No effect + # No effect o.to_inch() assert_equal(o.position, (0.1, 1.0)) assert_equal(o.width, 10.0) @@ -801,25 +854,27 @@ def test_obround_conversion(): assert_equal(o.width, 254.0) assert_equal(o.height, 2540.0) - #No effect + # No effect o.to_metric() assert_equal(o.position, (2.54, 25.4)) assert_equal(o.width, 254.0) assert_equal(o.height, 2540.0) + def test_obround_offset(): o = Obround((0, 0), 1, 2) o.offset(1, 0) - assert_equal(o.position,(1., 0.)) + assert_equal(o.position, (1., 0.)) o.offset(0, 1) - assert_equal(o.position,(1., 1.)) + assert_equal(o.position, (1., 1.)) + def test_polygon_ctor(): """ Test polygon creation """ - test_cases = (((0,0), 3, 5, 0), + test_cases = (((0, 0), 3, 5, 0), ((0, 0), 5, 6, 0), - ((1,1), 7, 7, 45)) + ((1, 1), 7, 7, 45)) for pos, sides, radius, hole_diameter in test_cases: p = Polygon(pos, sides, radius, hole_diameter) assert_equal(p.position, pos) @@ -827,73 +882,80 @@ def test_polygon_ctor(): assert_equal(p.radius, radius) assert_equal(p.hole_diameter, hole_diameter) + def test_polygon_bounds(): """ Test polygon bounding box calculation """ - p = Polygon((2,2), 3, 2, 0) + p = Polygon((2, 2), 3, 2, 0) xbounds, ybounds = p.bounding_box assert_array_almost_equal(xbounds, (0, 4)) assert_array_almost_equal(ybounds, (0, 4)) - p = Polygon((2,2), 3, 4, 0) + p = Polygon((2, 2), 3, 4, 0) xbounds, ybounds = p.bounding_box assert_array_almost_equal(xbounds, (-2, 6)) assert_array_almost_equal(ybounds, (-2, 6)) + def test_polygon_conversion(): p = Polygon((2.54, 25.4), 3, 254.0, 0, units='metric') - #No effect + # No effect p.to_metric() assert_equal(p.position, (2.54, 25.4)) assert_equal(p.radius, 254.0) - + p.to_inch() assert_equal(p.position, (0.1, 1.0)) assert_equal(p.radius, 10.0) - - #No effect + + # No effect p.to_inch() assert_equal(p.position, (0.1, 1.0)) assert_equal(p.radius, 10.0) p = Polygon((0.1, 1.0), 3, 10.0, 0, units='inch') - - #No effect + + # No effect p.to_inch() assert_equal(p.position, (0.1, 1.0)) assert_equal(p.radius, 10.0) - + p.to_metric() assert_equal(p.position, (2.54, 25.4)) assert_equal(p.radius, 254.0) - - #No effect + + # No effect p.to_metric() assert_equal(p.position, (2.54, 25.4)) assert_equal(p.radius, 254.0) + def test_polygon_offset(): p = Polygon((0, 0), 5, 10, 0) p.offset(1, 0) - assert_equal(p.position,(1., 0.)) + assert_equal(p.position, (1., 0.)) p.offset(0, 1) - assert_equal(p.position,(1., 1.)) + assert_equal(p.position, (1., 1.)) + def test_region_ctor(): """ Test Region creation """ - apt = Circle((0,0), 0) - lines = (Line((0,0), (1,0), apt), Line((1,0), (1,1), apt), Line((1,1), (0,1), apt), Line((0,1), (0,0), apt)) - points = ((0, 0), (1,0), (1,1), (0,1)) + apt = Circle((0, 0), 0) + lines = (Line((0, 0), (1, 0), apt), Line((1, 0), (1, 1), apt), + Line((1, 1), (0, 1), apt), Line((0, 1), (0, 0), apt)) + points = ((0, 0), (1, 0), (1, 1), (0, 1)) r = Region(lines) for i, p in enumerate(lines): assert_equal(r.primitives[i], p) + def test_region_bounds(): """ Test region bounding box calculation """ - apt = Circle((0,0), 0) - lines = (Line((0,0), (1,0), apt), Line((1,0), (1,1), apt), Line((1,1), (0,1), apt), Line((0,1), (0,0), apt)) + apt = Circle((0, 0), 0) + lines = (Line((0, 0), (1, 0), apt), Line((1, 0), (1, 1), apt), + Line((1, 1), (0, 1), apt), Line((0, 1), (0, 0), apt)) r = Region(lines) xbounds, ybounds = r.bounding_box assert_array_almost_equal(xbounds, (0, 1)) @@ -901,68 +963,76 @@ def test_region_bounds(): def test_region_offset(): - apt = Circle((0,0), 0) - lines = (Line((0,0), (1,0), apt), Line((1,0), (1,1), apt), Line((1,1), (0,1), apt), Line((0,1), (0,0), apt)) + apt = Circle((0, 0), 0) + lines = (Line((0, 0), (1, 0), apt), Line((1, 0), (1, 1), apt), + Line((1, 1), (0, 1), apt), Line((0, 1), (0, 0), apt)) r = Region(lines) xlim, ylim = r.bounding_box r.offset(0, 1) - assert_array_almost_equal((xlim, tuple([y+1 for y in ylim])), r.bounding_box) + new_xlim, new_ylim = r.bounding_box + assert_array_almost_equal(new_xlim, xlim) + assert_array_almost_equal(new_ylim, tuple([y + 1 for y in ylim])) + def test_round_butterfly_ctor(): """ Test round butterfly creation """ - test_cases = (((0,0), 3), ((0, 0), 5), ((1,1), 7)) + test_cases = (((0, 0), 3), ((0, 0), 5), ((1, 1), 7)) for pos, diameter in test_cases: b = RoundButterfly(pos, diameter) assert_equal(b.position, pos) assert_equal(b.diameter, diameter) - assert_equal(b.radius, diameter/2.) + assert_equal(b.radius, diameter / 2.) + def test_round_butterfly_ctor_validation(): """ Test RoundButterfly argument validation """ assert_raises(TypeError, RoundButterfly, 3, 5) - assert_raises(TypeError, RoundButterfly, (3,4,5), 5) + assert_raises(TypeError, RoundButterfly, (3, 4, 5), 5) + def test_round_butterfly_conversion(): b = RoundButterfly((2.54, 25.4), 254.0, units='metric') - - #No Effect + + # No Effect b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.diameter, (254.0)) - + b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.diameter, 10.0) - - #No effect + + # No effect b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.diameter, 10.0) b = RoundButterfly((0.1, 1.0), 10.0, units='inch') - - #No effect + + # No effect b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.diameter, 10.0) - + b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.diameter, (254.0)) - - #No Effect + + # No Effect b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.diameter, (254.0)) + def test_round_butterfly_offset(): b = RoundButterfly((0, 0), 1) b.offset(1, 0) - assert_equal(b.position,(1., 0.)) + assert_equal(b.position, (1., 0.)) b.offset(0, 1) - assert_equal(b.position,(1., 1.)) + assert_equal(b.position, (1., 1.)) + def test_round_butterfly_bounds(): """ Test RoundButterfly bounding box calculation @@ -972,20 +1042,23 @@ def test_round_butterfly_bounds(): assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) + def test_square_butterfly_ctor(): """ Test SquareButterfly creation """ - test_cases = (((0,0), 3), ((0, 0), 5), ((1,1), 7)) + test_cases = (((0, 0), 3), ((0, 0), 5), ((1, 1), 7)) for pos, side in test_cases: b = SquareButterfly(pos, side) assert_equal(b.position, pos) assert_equal(b.side, side) + def test_square_butterfly_ctor_validation(): """ Test SquareButterfly argument validation """ assert_raises(TypeError, SquareButterfly, 3, 5) - assert_raises(TypeError, SquareButterfly, (3,4,5), 5) + assert_raises(TypeError, SquareButterfly, (3, 4, 5), 5) + def test_square_butterfly_bounds(): """ Test SquareButterfly bounding box calculation @@ -995,51 +1068,54 @@ def test_square_butterfly_bounds(): assert_array_almost_equal(xbounds, (-1, 1)) assert_array_almost_equal(ybounds, (-1, 1)) + def test_squarebutterfly_conversion(): b = SquareButterfly((2.54, 25.4), 254.0, units='metric') - - #No effect + + # No effect b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.side, (254.0)) - + b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.side, 10.0) - - #No effect + + # No effect b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.side, 10.0) b = SquareButterfly((0.1, 1.0), 10.0, units='inch') - - #No effect + + # No effect b.to_inch() assert_equal(b.position, (0.1, 1.0)) assert_equal(b.side, 10.0) - + b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.side, (254.0)) - - #No effect + + # No effect b.to_metric() assert_equal(b.position, (2.54, 25.4)) assert_equal(b.side, (254.0)) + def test_square_butterfly_offset(): b = SquareButterfly((0, 0), 1) b.offset(1, 0) - assert_equal(b.position,(1., 0.)) + assert_equal(b.position, (1., 0.)) b.offset(0, 1) - assert_equal(b.position,(1., 1.)) + assert_equal(b.position, (1., 1.)) + def test_donut_ctor(): """ Test Donut primitive creation """ - test_cases = (((0,0), 'round', 3, 5), ((0, 0), 'square', 5, 7), - ((1,1), 'hexagon', 7, 9), ((2, 2), 'octagon', 9, 11)) + test_cases = (((0, 0), 'round', 3, 5), ((0, 0), 'square', 5, 7), + ((1, 1), 'hexagon', 7, 9), ((2, 2), 'octagon', 9, 11)) for pos, shape, in_d, out_d in test_cases: d = Donut(pos, shape, in_d, out_d) assert_equal(d.position, pos) @@ -1047,65 +1123,68 @@ def test_donut_ctor(): assert_equal(d.inner_diameter, in_d) assert_equal(d.outer_diameter, out_d) + def test_donut_ctor_validation(): assert_raises(TypeError, Donut, 3, 'round', 5, 7) assert_raises(TypeError, Donut, (3, 4, 5), 'round', 5, 7) assert_raises(ValueError, Donut, (0, 0), 'triangle', 3, 5) assert_raises(ValueError, Donut, (0, 0), 'round', 5, 3) + def test_donut_bounds(): d = Donut((0, 0), 'round', 0.0, 2.0) - assert_equal(d.lower_left, (-1.0, -1.0)) - assert_equal(d.upper_right, (1.0, 1.0)) xbounds, ybounds = d.bounding_box assert_equal(xbounds, (-1., 1.)) assert_equal(ybounds, (-1., 1.)) + def test_donut_conversion(): d = Donut((2.54, 25.4), 'round', 254.0, 2540.0, units='metric') - - #No effect + + # No effect d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.inner_diameter, 254.0) assert_equal(d.outer_diameter, 2540.0) - + d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.inner_diameter, 10.0) assert_equal(d.outer_diameter, 100.0) - - #No effect + + # No effect d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.inner_diameter, 10.0) assert_equal(d.outer_diameter, 100.0) d = Donut((0.1, 1.0), 'round', 10.0, 100.0, units='inch') - - #No effect + + # No effect d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.inner_diameter, 10.0) assert_equal(d.outer_diameter, 100.0) - + d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.inner_diameter, 254.0) assert_equal(d.outer_diameter, 2540.0) - - #No effect + + # No effect d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.inner_diameter, 254.0) assert_equal(d.outer_diameter, 2540.0) + def test_donut_offset(): d = Donut((0, 0), 'round', 1, 10) d.offset(1, 0) - assert_equal(d.position,(1., 0.)) + assert_equal(d.position, (1., 0.)) d.offset(0, 1) - assert_equal(d.position,(1., 1.)) + assert_equal(d.position, (1., 1.)) + def test_drill_ctor(): """ Test drill primitive creation @@ -1115,7 +1194,8 @@ def test_drill_ctor(): d = Drill(position, diameter, None) assert_equal(d.position, position) assert_equal(d.diameter, diameter) - assert_equal(d.radius, diameter/2.) + assert_equal(d.radius, diameter / 2.) + def test_drill_ctor_validation(): """ Test drill argument validation @@ -1133,46 +1213,48 @@ def test_drill_bounds(): assert_array_almost_equal(xbounds, (0, 2)) assert_array_almost_equal(ybounds, (1, 3)) + def test_drill_conversion(): d = Drill((2.54, 25.4), 254., None, units='metric') - - #No effect + + # No effect d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.diameter, 254.0) - + d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.diameter, 10.0) - - #No effect + + # No effect d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.diameter, 10.0) - d = Drill((0.1, 1.0), 10., None, units='inch') - - #No effect + + # No effect d.to_inch() assert_equal(d.position, (0.1, 1.0)) assert_equal(d.diameter, 10.0) - + d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.diameter, 254.0) - - #No effect + + # No effect d.to_metric() assert_equal(d.position, (2.54, 25.4)) assert_equal(d.diameter, 254.0) + def test_drill_offset(): d = Drill((0, 0), 1., None) d.offset(1, 0) - assert_equal(d.position,(1., 0.)) + assert_equal(d.position, (1., 0.)) d.offset(0, 1) - assert_equal(d.position,(1., 1.)) + assert_equal(d.position, (1., 1.)) + def test_drill_equality(): d = Drill((2.54, 25.4), 254., None) -- cgit From 8d5e782ccf220d77f0aad5a4e5605dc5cbe0f410 Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sat, 6 Aug 2016 09:51:58 +0800 Subject: Fix multiple problems with the merge. There are still errors, but I will intentionally leave them because future merges might resolve them --- gerber/tests/test_primitives.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index 261e6ef..e23d5f4 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -10,15 +10,13 @@ from .tests import * def test_primitive_smoketest(): p = Primitive() -<<<<<<< HEAD try: p.bounding_box assert_false(True, 'should have thrown the exception') except NotImplementedError: pass -======= #assert_raises(NotImplementedError, p.bounding_box) ->>>>>>> 5476da8... Fix a bunch of rendering bugs. + p.to_metric() p.to_inch() try: -- cgit From 5af19af190c1fb0f0c5be029d46d63e657dde4d9 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 21 Jan 2016 03:57:44 -0500 Subject: Commit partial merge so I can work on the plane --- gerber/tests/test_primitives.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'gerber/tests/test_primitives.py') diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py index e23d5f4..c49b558 100644 --- a/gerber/tests/test_primitives.py +++ b/gerber/tests/test_primitives.py @@ -204,7 +204,8 @@ def test_arc_bounds(): def test_arc_conversion(): c = Circle((0, 0), 25.4, units='metric') - a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0),'clockwise', c, 'single-quadrant', units='metric') + a = Arc((2.54, 25.4), (254.0, 2540.0), (25400.0, 254000.0), + 'clockwise', c, 'single-quadrant', units='metric') # No effect a.to_metric() @@ -227,7 +228,8 @@ def test_arc_conversion(): assert_equal(a.aperture.diameter, 1.0) c = Circle((0, 0), 1.0, units='inch') - a = Arc((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0),'clockwise', c, 'single-quadrant', units='inch') + a = Arc((0.1, 1.0), (10.0, 100.0), (1000.0, 10000.0), + 'clockwise', c, 'single-quadrant', units='inch') a.to_metric() assert_equal(a.start, (2.54, 25.4)) assert_equal(a.end, (254.0, 2540.0)) @@ -254,12 +256,14 @@ def test_circle_radius(): c = Circle((1, 1), 2) assert_equal(c.radius, 1) + def test_circle_hole_radius(): """ Test Circle primitive hole radius calculation """ c = Circle((1, 1), 4, 2) assert_equal(c.hole_radius, 1) + def test_circle_bounds(): """ Test Circle bounding box calculation """ @@ -301,7 +305,7 @@ def test_circle_conversion(): assert_equal(c.diameter, 10.) assert_equal(c.hole_diameter, 5.) - #no effect + # no effect c.to_inch() assert_equal(c.position, (0.1, 1.)) assert_equal(c.diameter, 10.) @@ -338,13 +342,14 @@ def test_circle_conversion(): assert_equal(c.diameter, 254.) assert_equal(c.hole_diameter, 127.) - #no effect + # no effect c.to_metric() assert_equal(c.position, (2.54, 25.4)) assert_equal(c.diameter, 254.) assert_equal(c.hole_diameter, 127.) + def test_circle_offset(): c = Circle((0, 0), 1) c.offset(1, 0) @@ -443,6 +448,7 @@ def test_rectangle_hole_radius(): assert_equal(0.5, r.hole_radius) + def test_rectangle_bounds(): """ Test rectangle bounding box calculation """ @@ -530,7 +536,7 @@ def test_rectangle_conversion(): assert_equal(r.hole_diameter, 127.0) r.to_metric() - assert_equal(r.position, (2.54,25.4)) + assert_equal(r.position, (2.54, 25.4)) assert_equal(r.width, 254.0) assert_equal(r.height, 2540.0) assert_equal(r.hole_diameter, 127.0) @@ -881,6 +887,7 @@ def test_polygon_ctor(): assert_equal(p.hole_diameter, hole_diameter) + def test_polygon_bounds(): """ Test polygon bounding box calculation """ @@ -1201,6 +1208,7 @@ def test_drill_ctor_validation(): assert_raises(TypeError, Drill, 3, 5, None) assert_raises(TypeError, Drill, (3,4,5), 5, None) + def test_drill_bounds(): d = Drill((0, 0), 2, None) xbounds, ybounds = d.bounding_box -- cgit