| 1234567891011121314151617181920212223242526272829303132333435 |
- from numpy import array, diag, dot, cos, sin
- from src import RectangularArea
- class BoundingBoxArea(RectangularArea):
- def __init__(self, x, y, points):
- super(BoundingBoxArea, self).__init__(x, y, 0, 0)
- self.points = array(points).T
- self.update_bounds()
- def translate_points(self, tx, ty):
- self.points += [[tx], [ty]]
- def scale_points(self, scale, cx, cy):
- self.translate_points(-cx, -cy)
- self.points = dot(diag([scale, scale]), self.points)
- self.translate_points(cx, cy)
- def rotate_points(self, angle, cx, cy):
- cosa = cos(angle)
- sina = sin(angle)
- mat = array([[cosa, -sina], [sina, cosa]])
- self.translate_points(-cx, -cy)
- self.points = dot(mat, self.points)
- self.translate_points(cx, cy)
- def update_bounds(self):
- min_x, min_y = self.points.min(1)
- max_x, max_y = self.points.max(1)
- self.set_size(max_x - min_x, max_y - min_y)
- if min_x or min_y:
- self.translate(min_x, min_y)
- self.translate_points(-min_x, -min_y)
|