Skip to content

Commit 9f6268f

Browse files
committed
Experimental rotation.setter for PolygonPixelRegion
1 parent e74ec80 commit 9f6268f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

regions/shapes/polygon.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def __init__(self, vertices, meta=None, visual=None,
7070
self.visual = visual or RegionVisual()
7171
self.origin = origin
7272
self.vertices = vertices + origin
73+
self._rotation = 0.0 * u.degree
7374

7475
@property
7576
def area(self):
@@ -301,6 +302,24 @@ def rotate(self, center, angle):
301302
vertices = self.vertices.rotate(center, angle)
302303
return self.copy(vertices=vertices)
303304

305+
@property
306+
def rotation(self):
307+
"""
308+
Rotation angle to apply in-place rotations (operating on this instance).
309+
Since `.setter` will apply the rotation directly on the vertices, this
310+
value will always be reset to 0.
311+
"""
312+
return self._rotation
313+
314+
@rotation.setter
315+
def rotation(self, angle):
316+
self.vertices = self.vertices.rotate(self.centroid, angle - self._rotation)
317+
self._rotation = 0.0 * u.degree
318+
if hasattr(self, '_mpl_selector'):
319+
self._mpl_selector.verts = list(zip(self.vertices.x, self.vertices.y))
320+
if getattr(self, '_mpl_selector_callback', None) is not None:
321+
self._mpl_selector_callback(self)
322+
304323

305324
class RegularPolygonPixelRegion(PolygonPixelRegion):
306325
"""

0 commit comments

Comments
 (0)