Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
Added bounding box method for Polygon object.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben van Staden authored and rubenvanstaden committed May 16, 2018
1 parent f55758c commit 5ca1d7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ MANIFEST
*.gds
docs/_*
.*.swp
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
20 changes: 20 additions & 0 deletions gdspy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,33 @@ def __init__(self, points, layer=0, datatype=0, verbose=True):
RuntimeWarning,
stacklevel=2)
self.layer = layer

if isinstance(points[0][0], list):
raise ValueError('points cannot be a 3D array')

self.points = numpy.array(points)
self.datatype = datatype

def __str__(self):
return "Polygon ({} vertices, layer {}, datatype {})".format(
len(self.points), self.layer, self.datatype)

def get_bounding_box(self):
"""
Returns the bounding box of the polygon.
Returns
-------
out : Numpy array[2,2] or ``None``
Bounding box of this polygon [[x_min, y_min], [x_max, y_max]], or
``None`` if the polygon is empty.
"""
if len(self.points) == 0:
return None

return numpy.array(((self.points[:, 0].min(), self.points[:, 1].min()),
(self.points[:, 0].max(), self.points[:, 1].max())))

def to_gds(self, multiplier):
"""
Convert this object to a GDSII element.
Expand Down

0 comments on commit 5ca1d7b

Please sign in to comment.