@@ -3056,37 +3056,35 @@ def _onmove(self, event):
3056
3056
state = self ._state
3057
3057
rotate = ('rotate' in state and
3058
3058
self ._active_handle in self ._corner_order )
3059
- eventpress = self ._eventpress
3059
+ xy = np .array ([event .xdata , event .ydata ])
3060
+ xy_press = np .array ([self ._eventpress .xdata , self ._eventpress .ydata ])
3061
+
3060
3062
# The calculations are done for rotation at zero: we apply inverse
3061
3063
# transformation to events except when we rotate and move
3062
3064
move = self ._active_handle == 'C'
3063
3065
if not move and not rotate :
3064
3066
inv_tr = self ._get_rotation_transform ().inverted ()
3065
- event .xdata , event .ydata = inv_tr .transform (
3066
- [event .xdata , event .ydata ])
3067
- eventpress .xdata , eventpress .ydata = inv_tr .transform (
3068
- [eventpress .xdata , eventpress .ydata ]
3069
- )
3067
+ xy = inv_tr .transform (xy )
3068
+ xy_press = inv_tr .transform (xy_press )
3070
3069
3071
- dx = event .xdata - eventpress .xdata
3072
- dy = event .ydata - eventpress .ydata
3070
+ dxy = xy - xy_press
3073
3071
# refmax is used when moving the corner handle with the square state
3074
3072
# and is the maximum between refx and refy
3075
3073
refmax = None
3076
3074
if self ._use_data_coordinates :
3077
- refx , refy = dx , dy
3075
+ refx , refy = dxy
3078
3076
else :
3079
3077
# Add 1e-6 to avoid divided by zero error
3080
- refx = event . xdata / (eventpress . xdata or 1E-6 )
3081
- refy = event . ydata / (eventpress . ydata or 1E-6 )
3078
+ refx = xy [ 0 ] / (xy_press [ 0 ] or 1E-6 )
3079
+ refy = xy [ 1 ] / (xy_press [ 1 ] or 1E-6 )
3082
3080
3083
3081
x0 , x1 , y0 , y1 = self ._extents_on_press
3084
3082
# rotate an existing shape
3085
3083
if rotate :
3086
3084
# calculate angle abc
3087
- a = np . array ([ eventpress . xdata , eventpress . ydata ])
3085
+ a = xy_press
3088
3086
b = np .array (self .center )
3089
- c = np . array ([ event . xdata , event . ydata ])
3087
+ c = xy
3090
3088
angle = (np .arctan2 (c [1 ]- b [1 ], c [0 ]- b [0 ]) -
3091
3089
np .arctan2 (a [1 ]- b [1 ], a [0 ]- b [0 ]))
3092
3090
self .rotation = np .rad2deg (self ._rotation_on_press + angle )
@@ -3104,19 +3102,19 @@ def _onmove(self, event):
3104
3102
if self ._active_handle in self ._corner_order :
3105
3103
refmax = max (refx , refy , key = abs )
3106
3104
if self ._active_handle in ['E' , 'W' ] or refmax == refx :
3107
- hw = event . xdata - center [0 ]
3105
+ hw = xy [ 0 ] - center [0 ]
3108
3106
hh = hw / self ._aspect_ratio_correction
3109
3107
else :
3110
- hh = event . ydata - center [1 ]
3108
+ hh = xy [ 1 ] - center [1 ]
3111
3109
hw = hh * self ._aspect_ratio_correction
3112
3110
else :
3113
3111
hw = size_on_press [0 ] / 2
3114
3112
hh = size_on_press [1 ] / 2
3115
3113
# cancel changes in perpendicular direction
3116
3114
if self ._active_handle in ['E' , 'W' ] + self ._corner_order :
3117
- hw = abs (event . xdata - center [0 ])
3115
+ hw = abs (xy [ 0 ] - center [0 ])
3118
3116
if self ._active_handle in ['N' , 'S' ] + self ._corner_order :
3119
- hh = abs (event . ydata - center [1 ])
3117
+ hh = abs (xy [ 1 ] - center [1 ])
3120
3118
3121
3119
x0 , x1 , y0 , y1 = (center [0 ] - hw , center [0 ] + hw ,
3122
3120
center [1 ] - hh , center [1 ] + hh )
@@ -3129,31 +3127,29 @@ def _onmove(self, event):
3129
3127
if 'S' in self ._active_handle :
3130
3128
y0 = y1
3131
3129
if self ._active_handle in ['E' , 'W' ] + self ._corner_order :
3132
- x1 = event . xdata
3130
+ x1 = xy [ 0 ]
3133
3131
if self ._active_handle in ['N' , 'S' ] + self ._corner_order :
3134
- y1 = event . ydata
3132
+ y1 = xy [ 1 ]
3135
3133
if 'square' in state :
3136
3134
# when using a corner, find which reference to use
3137
3135
if self ._active_handle in self ._corner_order :
3138
3136
refmax = max (refx , refy , key = abs )
3139
3137
if self ._active_handle in ['E' , 'W' ] or refmax == refx :
3140
- sign = np .sign (event . ydata - y0 )
3138
+ sign = np .sign (xy [ 1 ] - y0 )
3141
3139
y1 = y0 + sign * abs (x1 - x0 ) / \
3142
3140
self ._aspect_ratio_correction
3143
3141
else :
3144
- sign = np .sign (event . xdata - x0 )
3142
+ sign = np .sign (xy [ 0 ] - x0 )
3145
3143
x1 = x0 + sign * abs (y1 - y0 ) * \
3146
3144
self ._aspect_ratio_correction
3147
3145
3148
3146
# move existing shape
3149
3147
elif self ._active_handle == 'C' :
3150
3148
x0 , x1 , y0 , y1 = self ._extents_on_press
3151
- dx = event .xdata - eventpress .xdata
3152
- dy = event .ydata - eventpress .ydata
3153
- x0 += dx
3154
- x1 += dx
3155
- y0 += dy
3156
- y1 += dy
3149
+ x0 += dxy [0 ]
3150
+ x1 += dxy [0 ]
3151
+ y0 += dxy [1 ]
3152
+ y1 += dxy [1 ]
3157
3153
3158
3154
# new shape
3159
3155
else :
@@ -3162,7 +3158,7 @@ def _onmove(self, event):
3162
3158
# ignore_event_outside=True
3163
3159
if self .ignore_event_outside and self ._selection_completed :
3164
3160
return
3165
- center = [ eventpress . xdata , eventpress . ydata ]
3161
+ center = xy_press
3166
3162
dx = (event .xdata - center [0 ]) / 2.
3167
3163
dy = (event .ydata - center [1 ]) / 2.
3168
3164
0 commit comments