1 from __future__
import absolute_import, division, print_function
3 from ._polygon
import Polygon
9 return "%s(%s)" % (self.__class__.__name__, [p
for p
in self.getVertices()])
13 return self.__class__, (self.getVertices(),)
17 """Iterator over vertices""" 18 vertices = self.getVertices()
23 return [pt
for pt
in self][i]
27 return self.getNumEdges()
31 """point in polygon?""" 32 return self.contains(point)
35 def display(self, xy0=None, frame=1, ctype=None):
36 """Display polygon on existing frame in ds9""" 41 for p1, p2
in self.getEdges():
42 ds9.line((p1 - xy0, p2 - xy0), frame=frame, ctype=ctype)
45 def plot(self, axes=None, **kwargs):
46 """Plot polygon with matplotlib 48 @param axes: Matplotlib axes to use, or None 49 @param kwargs: Additional arguments for plotting (e.g., color, line type) 50 @return Matplotlib axes 54 import matplotlib.pyplot
as plt
57 for p1, p2
in self.getEdges():
58 x = (p1.getX(), p2.getX())
59 y = (p1.getY(), p2.getY())
60 axes.plot(x, y, **kwargs)
61 vertices = self.getVertices()
62 x = numpy.array([p[0]
for p
in vertices])
63 y = numpy.array([p[1]
for p
in vertices])
64 axes.scatter(x, y, **kwargs)
68 Polygon.__repr__ = __repr__
69 Polygon.__reduce__ = __reduce__
70 Polygon.__iter__ = __iter__
71 Polygon.__getitem__ = __getitem__
72 Polygon.__len__ = __len__
73 Polygon.__contains__ = __contains__
74 Polygon.display = display
def display(self, xy0=None, frame=1, ctype=None)
def __contains__(self, point)
def plot(self, axes=None, kwargs)