diff options
author | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-09-10 15:54:29 -0400 |
---|---|---|
committer | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-09-10 15:54:29 -0400 |
commit | b81c9d4bf96845ced3495eb158ec3a3c9e4dce3d (patch) | |
tree | ab939229a9735a4c0fd831daf0a11151d3c78d0a /gerber/primitives.py | |
parent | c92d2d9ea2853fd22b5ff51f211b03b4e660c551 (diff) | |
parent | cb2fa34e881a389cf8a4bc98fd12be662ff687f8 (diff) | |
download | gerbonara-b81c9d4bf96845ced3495eb158ec3a3c9e4dce3d.tar.gz gerbonara-b81c9d4bf96845ced3495eb158ec3a3c9e4dce3d.tar.bz2 gerbonara-b81c9d4bf96845ced3495eb158ec3a3c9e4dce3d.zip |
Merge pull request #40 from curtacircuitos/cairo-render-unification
Cairo render unification
Diffstat (limited to 'gerber/primitives.py')
-rw-r--r-- | gerber/primitives.py | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/gerber/primitives.py b/gerber/primitives.py index 00ecb12..0ac12af 100644 --- a/gerber/primitives.py +++ b/gerber/primitives.py @@ -63,7 +63,10 @@ class Primitive(object): else:
try:
if len(value) > 1:
- if isinstance(value[0], tuple):
+ if hasattr(value[0], 'to_inch'):
+ for v in value:
+ v.to_inch()
+ elif isinstance(value[0], tuple):
setattr(self, attr, [tuple(map(inch, point)) for point in value])
else:
setattr(self, attr, tuple(map(inch, value)))
@@ -81,7 +84,10 @@ class Primitive(object): else:
try:
if len(value) > 1:
- if isinstance(value[0], tuple):
+ if hasattr(value[0], 'to_metric'):
+ for v in value:
+ v.to_metric()
+ elif isinstance(value[0], tuple):
setattr(self, attr, [tuple(map(metric, point)) for point in value])
else:
setattr(self, attr, tuple(map(metric, value)))
@@ -584,23 +590,25 @@ class Polygon(Primitive): class Region(Primitive):
"""
"""
- def __init__(self, points, **kwargs):
+ def __init__(self, primitives, **kwargs):
super(Region, self).__init__(**kwargs)
- self.points = points
- self._to_convert = ['points']
+ self.primitives = primitives
+ self._to_convert = ['primitives']
@property
def bounding_box(self):
- x_list, y_list = zip(*self.points)
- min_x = min(x_list)
- max_x = max(x_list)
- min_y = min(y_list)
- max_y = max(y_list)
+ xlims, ylims = zip(*[p.bounding_box for p in self.primitives])
+ minx, maxx = zip(*xlims)
+ miny, maxy = zip(*ylims)
+ min_x = min(minx)
+ max_x = max(maxx)
+ min_y = min(miny)
+ max_y = max(maxy)
return ((min_x, max_x), (min_y, max_y))
def offset(self, x_offset=0, y_offset=0):
- self.points = [tuple(map(add, point, (x_offset, y_offset)))
- for point in self.points]
+ for p in self.primitives:
+ p.offset(x_offset, y_offset)
class RoundButterfly(Primitive):
|