@@ -1835,7 +1835,7 @@ def __init__(self, ax, onselect, useblit=False, button=None,
1835
1835
eventpress = _api .deprecate_privatize_attribute ("3.5" )
1836
1836
eventrelease = _api .deprecate_privatize_attribute ("3.5" )
1837
1837
state = _api .deprecate_privatize_attribute ("3.5" )
1838
- state_modifier_keys = _api .deprecate_privatize_attribute ("3.5 " )
1838
+ state_modifier_keys = _api .deprecate_privatize_attribute ("3.6 " )
1839
1839
1840
1840
def set_active (self , active ):
1841
1841
super ().set_active (active )
@@ -2803,7 +2803,8 @@ def onselect(eclick: MouseEvent, erelease: MouseEvent)
2803
2803
- "clear": Clear the current shape, default: "escape".
2804
2804
- "square": Make the shape square, default: "shift".
2805
2805
- "center": change the shape around its center, default: "ctrl".
2806
- - "rotate": Rotate the shape around its center, default: "r".
2806
+ - "rotate": Rotate the shape around its center between -45° and 45°,
2807
+ default: "r".
2807
2808
2808
2809
"square" and "center" can be combined. The square shape can be defined
2809
2810
in data or figure coordinates as determined by the
@@ -3061,7 +3062,8 @@ def _onmove(self, event):
3061
3062
eventpress = self ._eventpress
3062
3063
# The calculations are done for rotation at zero: we apply inverse
3063
3064
# transformation to events except when we rotate and move
3064
- if not (self ._active_handle == 'C' or rotate ):
3065
+ move = self ._active_handle == 'C'
3066
+ if not move and not rotate :
3065
3067
inv_tr = self ._get_rotation_transform ().inverted ()
3066
3068
event .xdata , event .ydata = inv_tr .transform (
3067
3069
[event .xdata , event .ydata ])
@@ -3078,8 +3080,8 @@ def _onmove(self, event):
3078
3080
refx , refy = dx , dy
3079
3081
else :
3080
3082
# Add 1e-6 to avoid divided by zero error
3081
- refx = event .xdata / (eventpress .xdata + 1e -6 )
3082
- refy = event .ydata / (eventpress .ydata + 1e -6 )
3083
+ refx = event .xdata / (eventpress .xdata or 1E -6 )
3084
+ refy = event .ydata / (eventpress .ydata or 1E -6 )
3083
3085
3084
3086
x0 , x1 , y0 , y1 = self ._extents_on_press
3085
3087
# rotate an existing shape
@@ -3099,6 +3101,7 @@ def _onmove(self, event):
3099
3101
3100
3102
# Keeping the center fixed
3101
3103
if 'center' in state :
3104
+ # hh, hw are half-height and half-width
3102
3105
if 'square' in state :
3103
3106
# when using a corner, find which reference to use
3104
3107
if self ._active_handle in self ._corner_order :
@@ -3277,14 +3280,17 @@ def extents(self, extents):
3277
3280
3278
3281
@property
3279
3282
def rotation (self ):
3280
- """Rotation in degree in interval [0, 45]."""
3283
+ """
3284
+ Rotation in degree in interval [-45°, 45°]. The rotation is limited in
3285
+ range to keep the implementation simple.
3286
+ """
3281
3287
return np .rad2deg (self ._rotation )
3282
3288
3283
3289
@rotation .setter
3284
3290
def rotation (self , value ):
3285
- # Restrict to a limited range of rotation [0 , 45] to avoid changing
3291
+ # Restrict to a limited range of rotation [-45° , 45° ] to avoid changing
3286
3292
# order of handles
3287
- if 0 <= v
5651
alue and value <= 45 :
3293
+ if - 45 <= value and value <= 45 :
3288
3294
self ._rotation = np .deg2rad (value )
3289
3295
# call extents setter to draw shape and update handles positions
3290
3296
self .extents = self .extents
0 commit comments