Hi all,
I want to write a function that returns a bounding box for a wxPython polygon as in wx.DC.DrawPolygon. Essentially, the polygon is defined in terms of a list of points [(x0,y0),(x1,y1),...,(xn,yn)].
The bounding rectangle is clearly (xmin, ymin, xmax, ymax), or in terms of the wx.Rect structure, wx.Rect(xmin, ymin, xmax-xmin, ymax-ymin).
Here's the code I have for finding it:
def get_bbox(self):
x_s = []
y_s = []
for x,y in self.coords:
x_s.append(x)
y_s.append(y)
x0 = min(x_s)
x1 = max(x_s)
y0 = min(y_s)
y1 = max(y_s)
return wx.Rect(x0+self.xoffset,y0+self.yoffset,x1-x0,y1-y0)
This is plainly klutzy, generating two separate lists for the x-coords and the y-coords by hand. Any suggestions for improvement?
Thanks,
Jeff