From 5df38c014fd09792995b2b12b1982c535c962c9a Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 28 Jan 2016 12:19:03 -0500 Subject: Cleanup, rendering fixes. fixed rendering of tented vias fixed rendering of semi-transparent layers fixed file type detection issues added some examples --- gerber/primitives.py | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) (limited to 'gerber/primitives.py') diff --git a/gerber/primitives.py b/gerber/primitives.py index 24e13a2..fa611df 100644 --- a/gerber/primitives.py +++ b/gerber/primitives.py @@ -166,7 +166,6 @@ class Primitive(object): in zip(self.position, (x_offset, y_offset))]) - def _changed(self): """ Clear memoized properties. @@ -568,11 +567,11 @@ class Rectangle(Primitive): @property def axis_aligned_width(self): - return (self._cos_theta * self.width + self._sin_theta * self.height) + 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) + return (self._cos_theta * self.height) + (self._sin_theta * self.width) class Diamond(Primitive): @@ -640,25 +639,24 @@ class Diamond(Primitive): @property def axis_aligned_width(self): - return (self._cos_theta * self.width + self._sin_theta * self.height) + 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) + return (self._cos_theta * self.height) + (self._sin_theta * self.width) class ChamferRectangle(Primitive): """ """ - - def __init__(self, position, width, height, chamfer, corners, **kwargs): + 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 + self._corners = corners if corners is not None else [True] * 4 self._to_convert = ['position', 'width', 'height', 'chamfer'] @property @@ -718,7 +716,37 @@ class ChamferRectangle(Primitive): @property def vertices(self): - # TODO + 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, corner, chamfered in enumerate((rect_corners, self.corners)): + 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 @@ -1142,3 +1170,4 @@ class TestRecord(Primitive): self.position = position self.net_name = net_name self.layer = layer + self._to_convert = ['position'] -- cgit