summaryrefslogtreecommitdiff
path: root/gerber
diff options
context:
space:
mode:
Diffstat (limited to 'gerber')
-rw-r--r--gerber/primitives.py10
-rw-r--r--gerber/tests/test_primitives.py14
2 files changed, 21 insertions, 3 deletions
diff --git a/gerber/primitives.py b/gerber/primitives.py
index f583ca9..b24b6c3 100644
--- a/gerber/primitives.py
+++ b/gerber/primitives.py
@@ -1666,11 +1666,15 @@ class Slot(Primitive):
def flashed(self):
return False
+ @property
def bounding_box(self):
if self._bounding_box is None:
- ll = tuple([c - self.diameter / 2. for c in self.position])
- ur = tuple([c + self.diameter / 2. for c in self.position])
- self._bounding_box = ((ll[0], ur[0]), (ll[1], ur[1]))
+ radius = self.diameter / 2.
+ min_x = min(self.start[0], self.end[0]) - radius
+ max_x = max(self.start[0], self.end[0]) + radius
+ min_y = min(self.start[1], self.end[1]) - radius
+ max_y = max(self.start[1], self.end[1]) + radius
+ self._bounding_box = ((min_x, max_x), (min_y, max_y))
return self._bounding_box
def offset(self, x_offset=0, y_offset=0):
diff --git a/gerber/tests/test_primitives.py b/gerber/tests/test_primitives.py
index 2fe5a4b..b932297 100644
--- a/gerber/tests/test_primitives.py
+++ b/gerber/tests/test_primitives.py
@@ -1343,3 +1343,17 @@ def test_drill_equality():
assert_equal(d, d1)
d1 = Drill((2.54, 25.4), 254.2)
assert_not_equal(d, d1)
+
+
+def test_slot_bounds():
+ """ Test Slot 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))), ]
+
+ for start, end, expected in cases:
+ s = Slot(start, end, 2.0)
+ assert_equal(s.bounding_box, expected)
+