diff --git a/camlib.py b/camlib.py index fbea85b8..893464fa 100644 --- a/camlib.py +++ b/camlib.py @@ -16,10 +16,46 @@ from shapely.geometry import box as shply_box from shapely.ops import cascaded_union -class Gerber(): +class Geometry: def __init__(self): # Units (in or mm) - self.units = 'in' + self.units = 'in' + + # Final geometry: MultiPolygon + self.solid_geometry = None + + def isolation_geometry(self, offset): + ''' + Creates contours around geometry at a given + offset distance. + ''' + return self.solid_geometry.buffer(offset) + + def bounds(self): + ''' + Returns coordinates of rectangular bounds + of geometry: (xmin, ymin, xmax, ymax). + ''' + if self.solid_geometry == None: + print "Warning: solid_geometry not computed yet." + return (0,0,0,0) + return self.solid_geometry.bounds + + def size(self): + ''' + Returns (width, height) of rectangular + bounds of geometry. + ''' + if self.solid_geometry == None: + print "Warning: solid_geometry not computed yet." + return 0 + bounds = self.bounds() + return (bounds[2]-bounds[0], bounds[3]-bounds[1]) + +class Gerber (Geometry): + def __init__(self): + # Initialize parent + Geometry.__init__(self) # Number format self.digits = 3 @@ -45,22 +81,6 @@ class Gerber(): # Flashes [{'loc':[float,float], 'aperture':dict}] self.flashes = [] - # Final geometry: MultiPolygon - self.solid_geometry = None - - def bounds(self): - if self.solid_geometry == None: - print "Warning: solid_geometry not computed yet." - return (0,0,0,0) - return self.solid_geometry.bounds - - def size(self): - if self.solid_geometry == None: - print "Warning: solid_geometry not computed yet." - return 0 - bounds = self.bounds() - return (bounds[2]-bounds[0], bounds[3]-bounds[1]) - def fix_regions(self): ''' Overwrites the region polygons with fixed diff --git a/camlib.pyc b/camlib.pyc index 97bc7448..09514b84 100644 Binary files a/camlib.pyc and b/camlib.pyc differ