Skip to content

Commit

Permalink
Experimental rotation.setter for PolygonPixelRegion
Browse files Browse the repository at this point in the history
  • Loading branch information
dhomeier committed Dec 30, 2021
1 parent e74ec80 commit 9f6268f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions regions/shapes/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self, vertices, meta=None, visual=None,
self.visual = visual or RegionVisual()
self.origin = origin
self.vertices = vertices + origin
self._rotation = 0.0 * u.degree

@property
def area(self):
Expand Down Expand Up @@ -301,6 +302,24 @@ def rotate(self, center, angle):
vertices = self.vertices.rotate(center, angle)
return self.copy(vertices=vertices)

@property
def rotation(self):
"""
Rotation angle to apply in-place rotations (operating on this instance).
Since `.setter` will apply the rotation directly on the vertices, this
value will always be reset to 0.
"""
return self._rotation

@rotation.setter
def rotation(self, angle):
self.vertices = self.vertices.rotate(self.centroid, angle - self._rotation)
self._rotation = 0.0 * u.degree
if hasattr(self, '_mpl_selector'):
self._mpl_selector.verts = list(zip(self.vertices.x, self.vertices.y))
if getattr(self, '_mpl_selector_callback', None) is not None:
self._mpl_selector_callback(self)


class RegularPolygonPixelRegion(PolygonPixelRegion):
"""
Expand Down

0 comments on commit 9f6268f

Please sign in to comment.