diff options
Diffstat (limited to 'gerbonara/gerber')
-rw-r--r-- | gerbonara/gerber/primitives.py | 429 | ||||
-rw-r--r-- | gerbonara/gerber/tests/test_primitives.py | 533 |
2 files changed, 0 insertions, 962 deletions
diff --git a/gerbonara/gerber/primitives.py b/gerbonara/gerber/primitives.py index afe6ec4..445b605 100644 --- a/gerbonara/gerber/primitives.py +++ b/gerbonara/gerber/primitives.py @@ -592,73 +592,6 @@ class Circle(Primitive): return nearly_equal(self.position, equiv_position)
-class Ellipse(Primitive):
- """
- """
- def __init__(self, position, width, height, **kwargs):
- super(Ellipse, self).__init__(**kwargs)
- validate_coordinates(position)
- self._position = position
- self._width = width
- self._height = height
- self._to_convert = ['position', 'width', 'height']
-
- @property
- def flashed(self):
- return True
-
- @property
- def position(self):
- return self._position
-
- @position.setter
- def position(self, value):
- self._changed()
- self._position = value
-
- @property
- def width(self):
- return self._width
-
- @width.setter
- def width(self, value):
- self._changed()
- self._width = value
-
- @property
- def height(self):
- return self._height
-
- @height.setter
- def height(self, value):
- self._changed()
- self._height = value
-
- @property
- def bounding_box(self):
- if self._bounding_box is None:
- min_x = self.position[0] - (self.axis_aligned_width / 2.0)
- max_x = self.position[0] + (self.axis_aligned_width / 2.0)
- min_y = self.position[1] - (self.axis_aligned_height / 2.0)
- max_y = self.position[1] + (self.axis_aligned_height / 2.0)
- self._bounding_box = ((min_x, min_y), (max_x, max_y))
- return self._bounding_box
-
- @property
- def axis_aligned_width(self):
- ux = (self.width / 2.) * math.cos(math.radians(self.rotation))
- vx = (self.height / 2.) * \
- math.cos(math.radians(self.rotation) + (math.pi / 2.))
- return 2 * math.sqrt((ux * ux) + (vx * vx))
-
- @property
- def axis_aligned_height(self):
- uy = (self.width / 2.) * math.sin(math.radians(self.rotation))
- vy = (self.height / 2.) * \
- math.sin(math.radians(self.rotation) + (math.pi / 2.))
- return 2 * math.sqrt((uy * uy) + (vy * vy))
-
-
class Rectangle(Primitive):
"""
When rotated, the rotation is about the center point.
@@ -783,285 +716,6 @@ class Rectangle(Primitive): return self.__str__()
-class Diamond(Primitive):
- """
- """
-
- def __init__(self, position, width, height, **kwargs):
- super(Diamond, self).__init__(**kwargs)
- validate_coordinates(position)
- self._position = position
- self._width = width
- self._height = height
- self._to_convert = ['position', 'width', 'height']
-
- @property
- def flashed(self):
- return True
-
- @property
- def position(self):
- return self._position
-
- @position.setter
- def position(self, value):
- self._changed()
- self._position = value
-
- @property
- def width(self):
- return self._width
-
- @width.setter
- def width(self, value):
- self._changed()
- self._width = value
-
- @property
- def height(self):
- return self._height
-
- @height.setter
- def height(self, value):
- self._changed()
- self._height = value
-
- @property
- def bounding_box(self):
- if self._bounding_box is None:
- ll = (self.position[0] - (self.axis_aligned_width / 2.),
- self.position[1] - (self.axis_aligned_height / 2.))
- ur = (self.position[0] + (self.axis_aligned_width / 2.),
- self.position[1] + (self.axis_aligned_height / 2.))
- self._bounding_box = ((ll[0], ll[1]), (ur[0], ur[1]))
- return self._bounding_box
-
- @property
- def vertices(self):
- if self._vertices is None:
- delta_w = self.width / 2.
- delta_h = self.height / 2.
- top = (self.position[0], (self.position[1] + delta_h))
- right = ((self.position[0] + delta_w), self.position[1])
- bottom = (self.position[0], (self.position[1] - delta_h))
- left = ((self.position[0] - delta_w), self.position[1])
- self._vertices = [(((x * self._cos_theta) - (y * self._sin_theta)),
- ((x * self._sin_theta) + (y * self._cos_theta)))
- for x, y in [top, right, bottom, left]]
- return self._vertices
-
- @property
- def axis_aligned_width(self):
- return (self._cos_theta * self.width + self._sin_theta * self.height)
-
- @property
- def axis_aligned_height(self):
- return (self._cos_theta * self.height + self._sin_theta * self.width)
-
-
-class ChamferRectangle(Primitive):
- """
- """
- def __init__(self, position, width, height, chamfer, corners=None, **kwargs):
- super(ChamferRectangle, self).__init__(**kwargs)
- validate_coordinates(position)
- self._position = position
- self._width = width
- self._height = height
- self._chamfer = chamfer
- self._corners = corners if corners is not None else [True] * 4
- self._to_convert = ['position', 'width', 'height', 'chamfer']
-
- @property
- def flashed(self):
- return True
-
- @property
- def position(self):
- return self._position
-
- @position.setter
- def position(self, value):
- self._changed()
- self._position = value
-
- @property
- def width(self):
- return self._width
-
- @width.setter
- def width(self, value):
- self._changed()
- self._width = value
-
- @property
- def height(self):
- return self._height
-
- @height.setter
- def height(self, value):
- self._changed()
- self._height = value
-
- @property
- def chamfer(self):
- return self._chamfer
-
- @chamfer.setter
- def chamfer(self, value):
- self._changed()
- self._chamfer = value
-
- @property
- def corners(self):
- return self._corners
-
- @corners.setter
- def corners(self, value):
- self._changed()
- self._corners = value
-
- @property
- def bounding_box(self):
- if self._bounding_box is None:
- ll = (self.position[0] - (self.axis_aligned_width / 2.),
- self.position[1] - (self.axis_aligned_height / 2.))
- ur = (self.position[0] + (self.axis_aligned_width / 2.),
- self.position[1] + (self.axis_aligned_height / 2.))
- self._bounding_box = ((ll[0], ll[1]), (ur[1], ur[1]))
- return self._bounding_box
-
- @property
- def vertices(self):
- if self._vertices is None:
- vertices = []
- delta_w = self.width / 2.
- delta_h = self.height / 2.
- # order is UR, UL, LL, LR
- rect_corners = [
- ((self.position[0] + delta_w), (self.position[1] + delta_h)),
- ((self.position[0] - delta_w), (self.position[1] + delta_h)),
- ((self.position[0] - delta_w), (self.position[1] - delta_h)),
- ((self.position[0] + delta_w), (self.position[1] - delta_h))
- ]
- for idx, params in enumerate(zip(rect_corners, self.corners)):
- corner, chamfered = params
- x, y = corner
- if chamfered:
- if idx == 0:
- vertices.append((x - self.chamfer, y))
- vertices.append((x, y - self.chamfer))
- elif idx == 1:
- vertices.append((x + self.chamfer, y))
- vertices.append((x, y - self.chamfer))
- elif idx == 2:
- vertices.append((x + self.chamfer, y))
- vertices.append((x, y + self.chamfer))
- elif idx == 3:
- vertices.append((x - self.chamfer, y))
- vertices.append((x, y + self.chamfer))
- else:
- vertices.append(corner)
- self._vertices = [((x * self._cos_theta - y * self._sin_theta),
- (x * self._sin_theta + y * self._cos_theta))
- for x, y in vertices]
- return self._vertices
-
- @property
- def axis_aligned_width(self):
- return (self._cos_theta * self.width +
- self._sin_theta * self.height)
-
- @property
- def axis_aligned_height(self):
- return (self._cos_theta * self.height +
- self._sin_theta * self.width)
-
-
-class RoundRectangle(Primitive):
- """
- """
-
- def __init__(self, position, width, height, radius, corners, **kwargs):
- super(RoundRectangle, self).__init__(**kwargs)
- validate_coordinates(position)
- self._position = position
- self._width = width
- self._height = height
- self._radius = radius
- self._corners = corners
- self._to_convert = ['position', 'width', 'height', 'radius']
-
- @property
- def flashed(self):
- return True
-
- @property
- def position(self):
- return self._position
-
- @position.setter
- def position(self, value):
- self._changed()
- self._position = value
-
- @property
- def width(self):
- return self._width
-
- @width.setter
- def width(self, value):
- self._changed()
- self._width = value
-
- @property
- def height(self):
- return self._height
-
- @height.setter
- def height(self, value):
- self._changed()
- self._height = value
-
- @property
- def radius(self):
- return self._radius
-
- @radius.setter
- def radius(self, value):
- self._changed()
- self._radius = value
-
- @property
- def corners(self):
- return self._corners
-
- @corners.setter
- def corners(self, value):
- self._changed()
- self._corners = value
-
- @property
- def bounding_box(self):
- if self._bounding_box is None:
- ll = (self.position[0] - (self.axis_aligned_width / 2.),
- self.position[1] - (self.axis_aligned_height / 2.))
- ur = (self.position[0] + (self.axis_aligned_width / 2.),
- self.position[1] + (self.axis_aligned_height / 2.))
- self._bounding_box = ((ll[0], ll[1]), (ur[0], ur[1]))
- return self._bounding_box
-
- @property
- def axis_aligned_width(self):
- return (self._cos_theta * self.width +
- self._sin_theta * self.height)
-
- @property
- def axis_aligned_height(self):
- return (self._cos_theta * self.height +
- self._sin_theta * self.width)
-
-
class Obround(Primitive):
def __init__(self, position, width, height, hole_diameter=0,
hole_width=0,hole_height=0, **kwargs):
@@ -1448,89 +1102,6 @@ class Region(Primitive): for p in self.primitives:
p.offset(x_offset, y_offset)
-class Donut(Primitive):
- """ A Shape with an identical concentric shape removed from its center
- """
-
- def __init__(self, position, shape, inner_diameter,
- outer_diameter, **kwargs):
- super(Donut, self).__init__(**kwargs)
- validate_coordinates(position)
- self.position = position
- if shape not in ('round', 'square', 'hexagon', 'octagon'):
- raise ValueError(
- 'Valid shapes are round, square, hexagon or octagon')
- self.shape = shape
- if inner_diameter >= outer_diameter:
- raise ValueError(
- 'Outer diameter must be larger than inner diameter.')
- self.inner_diameter = inner_diameter
- self.outer_diameter = outer_diameter
- if self.shape in ('round', 'square', 'octagon'):
- self.width = outer_diameter
- self.height = outer_diameter
- else:
- # Hexagon
- self.width = 0.5 * math.sqrt(3.) * outer_diameter
- self.height = outer_diameter
-
- self._to_convert = ['position', 'width',
- 'height', 'inner_diameter', 'outer_diameter']
-
- # TODO This does not reset bounding box correctly
-
- @property
- def flashed(self):
- return True
-
- @property
- def lower_left(self):
- return (self.position[0] - (self.width / 2.),
- self.position[1] - (self.height / 2.))
-
- @property
- def upper_right(self):
- return (self.position[0] + (self.width / 2.),
- self.position[1] + (self.height / 2.))
-
- @property
- def bounding_box(self):
- if self._bounding_box is None:
- ll = (self.position[0] - (self.width / 2.),
- self.position[1] - (self.height / 2.))
- ur = (self.position[0] + (self.width / 2.),
- self.position[1] + (self.height / 2.))
- self._bounding_box = (ll, ur)
- return self._bounding_box
-
-
-class SquareRoundDonut(Primitive):
- """ A Square with a circular cutout in the center
- """
-
- def __init__(self, position, inner_diameter, outer_diameter, **kwargs):
- super(SquareRoundDonut, self).__init__(**kwargs)
- validate_coordinates(position)
- self.position = position
- if inner_diameter >= outer_diameter:
- raise ValueError(
- 'Outer diameter must be larger than inner diameter.')
- self.inner_diameter = inner_diameter
- self.outer_diameter = outer_diameter
- self._to_convert = ['position', 'inner_diameter', 'outer_diameter']
-
- @property
- def flashed(self):
- return True
-
- @property
- def bounding_box(self):
- if self._bounding_box is None:
- ll = tuple([c - self.outer_diameter / 2. for c in self.position])
- ur = tuple([c + self.outer_diameter / 2. for c in self.position])
- self._bounding_box = (ll, ur)
- return self._bounding_box
-
class Drill(Primitive):
""" A drill hole
diff --git a/gerbonara/gerber/tests/test_primitives.py b/gerbonara/gerber/tests/test_primitives.py index d4ee653..3f8df51 100644 --- a/gerbonara/gerber/tests/test_primitives.py +++ b/gerbonara/gerber/tests/test_primitives.py @@ -406,76 +406,6 @@ def test_circle_offset(): assert c.position == (1.0, 1.0) -def test_ellipse_ctor(): - """ Test ellipse creation - """ - e = Ellipse((2, 2), 3, 2) - assert e.position == (2, 2) - assert e.width == 3 - assert e.height == 2 - - -def test_ellipse_bounds(): - """ Test ellipse bounding box calculation - """ - e = Ellipse((2, 2), 4, 2) - assert e.bounding_box == ((0, 1), (4, 3)) - e = Ellipse((2, 2), 4, 2, rotation=90) - assert e.bounding_box == ((1, 0), (3, 4)) - e = Ellipse((2, 2), 4, 2, rotation=180) - assert e.bounding_box == ((0, 1), (4, 3)) - e = Ellipse((2, 2), 4, 2, rotation=270) - assert e.bounding_box == ((1, 0), (3, 4)) - - -def test_ellipse_conversion(): - e = Ellipse((2.54, 25.4), 254.0, 2540.0, units="metric") - - # No effect - e.to_metric() - assert e.position == (2.54, 25.4) - assert e.width == 254.0 - assert e.height == 2540.0 - - e.to_inch() - assert e.position == (0.1, 1.0) - assert e.width == 10.0 - assert e.height == 100.0 - - # No effect - e.to_inch() - assert e.position == (0.1, 1.0) - assert e.width == 10.0 - assert e.height == 100.0 - - e = Ellipse((0.1, 1.0), 10.0, 100.0, units="inch") - - # no effect - e.to_inch() - assert e.position == (0.1, 1.0) - assert e.width == 10.0 - assert e.height == 100.0 - - e.to_metric() - assert e.position == (2.54, 25.4) - assert e.width == 254.0 - assert e.height == 2540.0 - - # No effect - e.to_metric() - assert e.position == (2.54, 25.4) - assert e.width == 254.0 - assert e.height == 2540.0 - - -def test_ellipse_offset(): - e = Ellipse((0, 0), 1, 2) - e.offset(1, 0) - assert e.position == (1.0, 0.0) - e.offset(0, 1) - assert e.position == (1.0, 1.0) - - def test_rectangle_ctor(): """ Test rectangle creation """ @@ -635,199 +565,6 @@ def test_rectangle_offset(): assert r.position == (1.0, 1.0) -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 d.position == pos - assert d.width == width - assert d.height == height - - -def test_diamond_bounds(): - """ Test diamond bounding box calculation - """ - d = Diamond((0, 0), 2, 2) - bounds = d.bounding_box - pytest.approx(bounds[0], (-1, -1)) - pytest.approx(bounds[1], (1, 1)) - d = Diamond((0, 0), math.sqrt(2), math.sqrt(2), rotation=45) - bounds = d.bounding_box - pytest.approx(bounds[0], (-1, -1)) - pytest.approx(bounds[1], (1, 1)) - - -def test_diamond_conversion(): - d = Diamond((2.54, 25.4), 254.0, 2540.0, units="metric") - - d.to_metric() - assert d.position == (2.54, 25.4) - assert d.width == 254.0 - assert d.height == 2540.0 - - d.to_inch() - assert d.position == (0.1, 1.0) - assert d.width == 10.0 - assert d.height == 100.0 - - d.to_inch() - assert d.position == (0.1, 1.0) - assert d.width == 10.0 - assert d.height == 100.0 - - d = Diamond((0.1, 1.0), 10.0, 100.0, units="inch") - - d.to_inch() - assert d.position == (0.1, 1.0) - assert d.width == 10.0 - assert d.height == 100.0 - - d.to_metric() - assert d.position == (2.54, 25.4) - assert d.width == 254.0 - assert d.height == 2540.0 - - d.to_metric() - assert d.position == (2.54, 25.4) - assert d.width == 254.0 - assert d.height == 2540.0 - - -def test_diamond_offset(): - d = Diamond((0, 0), 1, 2) - d.offset(1, 0) - assert d.position == (1.0, 0.0) - d.offset(0, 1) - assert d.position == (1.0, 1.0) - - -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 r.position == pos - assert r.width == width - assert r.height == height - assert r.chamfer == chamfer - pytest.approx(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)) - bounds = r.bounding_box - pytest.approx(bounds[0], (-1, -1)) - pytest.approx(bounds[1], (1, 1)) - r = ChamferRectangle((0, 0), 2, 2, 0.2, (True, True, False, False), rotation=45) - bounds = r.bounding_box - pytest.approx(bounds[0], (-math.sqrt(2), -math.sqrt(2))) - pytest.approx(bounds[1], (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.to_metric() - assert r.position == (2.54, 25.4) - assert r.width == 254.0 - assert r.height == 2540.0 - assert r.chamfer == 0.254 - - r.to_inch() - assert r.position == (0.1, 1.0) - assert r.width == 10.0 - assert r.height == 100.0 - assert r.chamfer == 0.01 - - r.to_inch() - assert r.position == (0.1, 1.0) - assert r.width == 10.0 - assert r.height == 100.0 - assert 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 r.position == (0.1, 1.0) - assert r.width == 10.0 - assert r.height == 100.0 - assert r.chamfer == 0.01 - - r.to_metric() - assert r.position == (2.54, 25.4) - assert r.width == 254.0 - assert r.height == 2540.0 - assert r.chamfer == 0.254 - - r.to_metric() - assert r.position == (2.54, 25.4) - assert r.width == 254.0 - assert r.height == 2540.0 - assert 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 r.position == (1.0, 0.0) - r.offset(0, 1) - assert r.position == (1.0, 1.0) - - -def test_chamfer_rectangle_vertices(): - TEST_VECTORS = [ - ( - 1.0, - (True, True, True, True), - ( - (-2.5, -1.5), - (-2.5, 1.5), - (-1.5, 2.5), - (1.5, 2.5), - (2.5, 1.5), - (2.5, -1.5), - (1.5, -2.5), - (-1.5, -2.5), - ), - ), - ( - 1.0, - (True, False, False, False), - ((-2.5, -2.5), (-2.5, 2.5), (1.5, 2.5), (2.5, 1.5), (2.5, -2.5)), - ), - ( - 1.0, - (False, True, False, False), - ((-2.5, -2.5), (-2.5, 1.5), (-1.5, 2.5), (2.5, 2.5), (2.5, -2.5)), - ), - ( - 1.0, - (False, False, True, False), - ((-2.5, -1.5), (-2.5, 2.5), (2.5, 2.5), (2.5, -2.5), (-1.5, -2.5)), - ), - ( - 1.0, - (False, False, False, True), - ((-2.5, -2.5), (-2.5, 2.5), (2.5, 2.5), (2.5, -1.5), (1.5, -2.5)), - ), - ] - for chamfer, corners, expected in TEST_VECTORS: - r = ChamferRectangle((0, 0), 5, 5, chamfer, corners) - assert set(r.vertices) == set(expected) - - def test_round_rectangle_ctor(): """ Test round rectangle creation """ @@ -858,60 +595,6 @@ def test_round_rectangle_bounds(): pytest.approx(bounds[1], (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.to_metric() - assert r.position == (2.54, 25.4) - assert r.width == 254.0 - assert r.height == 2540.0 - assert r.radius == 0.254 - - r.to_inch() - assert r.position == (0.1, 1.0) - assert r.width == 10.0 - assert r.height == 100.0 - assert r.radius == 0.01 - - r.to_inch() - assert r.position == (0.1, 1.0) - assert r.width == 10.0 - assert r.height == 100.0 - assert 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 r.position == (0.1, 1.0) - assert r.width == 10.0 - assert r.height == 100.0 - assert r.radius == 0.01 - - r.to_metric() - assert r.position == (2.54, 25.4) - assert r.width == 254.0 - assert r.height == 2540.0 - assert r.radius == 0.254 - - r.to_metric() - assert r.position == (2.54, 25.4) - assert r.width == 254.0 - assert r.height == 2540.0 - assert 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 r.position == (1.0, 0.0) - r.offset(0, 1) - assert r.position == (1.0, 1.0) - - def test_obround_ctor(): """ Test obround creation """ @@ -1119,222 +802,6 @@ def test_region_offset(): pytest.approx(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)) - for pos, diameter in test_cases: - b = RoundButterfly(pos, diameter) - assert b.position == pos - assert b.diameter == diameter - assert b.radius == diameter / 2.0 - - -def test_round_butterfly_ctor_validation(): - """ Test RoundButterfly argument validation - """ - pytest.raises(TypeError, RoundButterfly, 3, 5) - pytest.raises(TypeError, RoundButterfly, (3, 4, 5), 5) - - -def test_round_butterfly_conversion(): - b = RoundButterfly((2.54, 25.4), 254.0, units="metric") - - # No Effect - b.to_metric() - assert b.position == (2.54, 25.4) - assert b.diameter == (254.0) - - b.to_inch() - assert b.position == (0.1, 1.0) - assert b.diameter == 10.0 - - # No effect - b.to_inch() - assert b.position == (0.1, 1.0) - assert b.diameter == 10.0 - - b = RoundButterfly((0.1, 1.0), 10.0, units="inch") - - # No effect - b.to_inch() - assert b.position == (0.1, 1.0) - assert b.diameter == 10.0 - - b.to_metric() - assert b.position == (2.54, 25.4) - assert b.diameter == (254.0) - - # No Effect - b.to_metric() - assert b.position == (2.54, 25.4) - assert b.diameter == (254.0) - - -def test_round_butterfly_offset(): - b = RoundButterfly((0, 0), 1) - b.offset(1, 0) - assert b.position == (1.0, 0.0) - b.offset(0, 1) - assert b.position == (1.0, 1.0) - - -def test_round_butterfly_bounds(): - """ Test RoundButterfly bounding box calculation - """ - b = RoundButterfly((0, 0), 2) - bounds = b.bounding_box - pytest.approx(bounds[0], (-1, -1)) - pytest.approx(bounds[1], (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 b.position == pos - assert b.side == side - - -def test_square_butterfly_ctor_validation(): - """ Test SquareButterfly argument validation - """ - pytest.raises(TypeError, SquareButterfly, 3, 5) - pytest.raises(TypeError, SquareButterfly, (3, 4, 5), 5) - - -def test_square_butterfly_bounds(): - """ Test SquareButterfly bounding box calculation - """ - b = SquareButterfly((0, 0), 2) - bounds = b.bounding_box - pytest.approx(bounds[0], (-1, -1)) - pytest.approx(bounds[1], (1, 1)) - - -def test_squarebutterfly_conversion(): - b = SquareButterfly((2.54, 25.4), 254.0, units="metric") - - # No effect - b.to_metric() - assert b.position == (2.54, 25.4) - assert b.side == (254.0) - - b.to_inch() - assert b.position == (0.1, 1.0) - assert b.side == 10.0 - - # No effect - b.to_inch() - assert b.position == (0.1, 1.0) - assert b.side == 10.0 - - b = SquareButterfly((0.1, 1.0), 10.0, units="inch") - - # No effect - b.to_inch() - assert b.position == (0.1, 1.0) - assert b.side == 10.0 - - b.to_metric() - assert b.position == (2.54, 25.4) - assert b.side == (254.0) - - # No effect - b.to_metric() - assert b.position == (2.54, 25.4) - assert b.side == (254.0) - - -def test_square_butterfly_offset(): - b = SquareButterfly((0, 0), 1) - b.offset(1, 0) - assert b.position == (1.0, 0.0) - b.offset(0, 1) - assert b.position == (1.0, 1.0) - - -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 d.position == pos - assert d.shape == shape - assert d.inner_diameter == in_d - assert d.outer_diameter == out_d - - -def test_donut_ctor_validation(): - pytest.raises(TypeError, Donut, 3, "round", 5, 7) - pytest.raises(TypeError, Donut, (3, 4, 5), "round", 5, 7) - pytest.raises(ValueError, Donut, (0, 0), "triangle", 3, 5) - pytest.raises(ValueError, Donut, (0, 0), "round", 5, 3) - - -def test_donut_bounds(): - d = Donut((0, 0), "round", 0.0, 2.0) - bounds = d.bounding_box - assert bounds[0] == (-1.0, -1.0) - assert bounds[1] == (1.0, 1.0) - - -def test_donut_conversion(): - d = Donut((2.54, 25.4), "round", 254.0, 2540.0, units="metric") - - # No effect - d.to_metric() - assert d.position == (2.54, 25.4) - assert d.inner_diameter == 254.0 - assert d.outer_diameter == 2540.0 - - d.to_inch() - assert d.position == (0.1, 1.0) - assert d.inner_diameter == 10.0 - assert d.outer_diameter == 100.0 - - # No effect - d.to_inch() - assert d.position == (0.1, 1.0) - assert d.inner_diameter == 10.0 - assert d.outer_diameter == 100.0 - - d = Donut((0.1, 1.0), "round", 10.0, 100.0, units="inch") - - # No effect - d.to_inch() - assert d.position == (0.1, 1.0) - assert d.inner_diameter == 10.0 - assert d.outer_diameter == 100.0 - - d.to_metric() - assert d.position == (2.54, 25.4) - assert d.inner_diameter == 254.0 - assert d.outer_diameter == 2540.0 - - # No effect - d.to_metric() - assert d.position == (2.54, 25.4) - assert d.inner_diameter == 254.0 - assert d.outer_diameter == 2540.0 - - -def test_donut_offset(): - d = Donut((0, 0), "round", 1, 10) - d.offset(1, 0) - assert d.position == (1.0, 0.0) - d.offset(0, 1) - assert d.position == (1.0, 1.0) - - def test_drill_ctor(): """ Test drill primitive creation """ |