summaryrefslogtreecommitdiff
path: root/gerber/primitives.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2015-02-13 09:37:27 -0500
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2015-02-13 09:37:27 -0500
commit5e23d07bcb5103b4607c6ad591a2a547c97ee1f6 (patch)
treefdc7989cc6d4fe200d61267b6b9c228dcce44c2c /gerber/primitives.py
parent8f69c1dfa281b6486c8fce16c1d58acef70c7ae7 (diff)
downloadgerbonara-5e23d07bcb5103b4607c6ad591a2a547c97ee1f6.tar.gz
gerbonara-5e23d07bcb5103b4607c6ad591a2a547c97ee1f6.tar.bz2
gerbonara-5e23d07bcb5103b4607c6ad591a2a547c97ee1f6.zip
Fix rendering for line with rectangular aperture per #12. Still need to do the same for arcs.
Diffstat (limited to 'gerber/primitives.py')
-rw-r--r--gerber/primitives.py72
1 files changed, 64 insertions, 8 deletions
diff --git a/gerber/primitives.py b/gerber/primitives.py
index a239cab..1663a53 100644
--- a/gerber/primitives.py
+++ b/gerber/primitives.py
@@ -64,14 +64,70 @@ class Line(Primitive):
angle = math.atan2(delta_y, delta_x)
return angle
- #@property
- #def bounding_box(self):
- # width_2 = self.width / 2.
- # min_x = min(self.start[0], self.end[0]) - width_2
- # max_x = max(self.start[0], self.end[0]) + width_2
- # min_y = min(self.start[1], self.end[1]) - width_2
- # max_y = max(self.start[1], self.end[1]) + width_2
- # return ((min_x, max_x), (min_y, max_y))
+ @property
+ def bounding_box(self):
+ if isinstance(self.aperture, Circle):
+ width_2 = self.aperture.radius
+ height_2 = width_2
+ else:
+ width_2 = self.aperture.width / 2.
+ height_2 = self.aperture.height / 2.
+ min_x = min(self.start[0], self.end[0]) - width_2
+ max_x = max(self.start[0], self.end[0]) + width_2
+ min_y = min(self.start[1], self.end[1]) - height_2
+ max_y = max(self.start[1], self.end[1]) + height_2
+ return ((min_x, max_x), (min_y, max_y))
+
+ @property
+ def vertices(self):
+ if not isinstance(self.aperture, Rectangle):
+ return None
+ else:
+ start = self.start
+ end = self.end
+ width = self.aperture.width
+ height = self.aperture.height
+
+ # Find all the corners of the start and end position
+ start_ll = (start[0] - (width / 2.),
+ start[1] - (height / 2.))
+ start_lr = (start[0] - (width / 2.),
+ start[1] + (height / 2.))
+ start_ul = (start[0] + (width / 2.),
+ start[1] - (height / 2.))
+ start_ur = (start[0] + (width / 2.),
+ start[1] + (height / 2.))
+ end_ll = (end[0] - (width / 2.),
+ end[1] - (height / 2.))
+ end_lr = (end[0] - (width / 2.),
+ end[1] + (height / 2.))
+ end_ul = (end[0] + (width / 2.),
+ end[1] - (height / 2.))
+ end_ur = (end[0] + (width / 2.),
+ end[1] + (height / 2.))
+
+ if end[0] == start[0] and end[1] == start[1]:
+ return (start_ll, start_lr, start_ur, start_ul)
+ elif end[0] == start[0] and end[1] > start[1]:
+ return (start_ll, start_lr, end_ur, end_ul)
+ elif end[0] > start[0] and end[1] > start[1]:
+ return (start_ll, start_lr, end_lr, end_ur, end_ul, start_ul)
+ elif end[0] > start[0] and end[1] == start[1]:
+ return (start_ll, end_lr, end_ur, start_ul)
+ elif end[0] > start[0] and end[1] < start[1]:
+ return (start_ll, end_ll, end_lr, end_ur, start_ur, start_ul)
+ elif end[0] == start[0] and end[1] < start[1]:
+ return (end_ll, end_lr, start_ur, start_ul)
+ elif end[0] < start[0] and end[1] < start[1]:
+ return (end_ll, end_lr, start_lr, start_ur, start_ul, end_ul)
+ elif end[0] < start[0] and end[1] == start[1]:
+ return (end_ll, start_lr, start_ur, end_ul)
+ elif end[0] < start[0] and end[1] > start[1]:
+ return (start_ll, start_lr, start_ur, end_ur, end_ul, end_ll)
+ else:
+ return None
+
+
class Arc(Primitive):