@@ -2970,8 +2970,8 @@ def _onmove(self, event):
2970
2970
# resize an existing shape
2971
2971
if self ._active_handle and self ._active_handle != 'C' :
2972
2972
x0 , x1 , y0 , y1 = self ._extents_on_press
2973
- sizepress = [x1 - x0 , y1 - y0 ]
2974
- center = [x0 + sizepress [0 ] / 2 , y0 + sizepress [1 ] / 2 ]
2973
+ size_on_press = [x1 - x0 , y1 - y0 ]
2974
+ center = [x0 + size_on_press [0 ] / 2 , y0 + size_on_press [1 ] / 2 ]
2975
2975
dx = event .xdata - self ._eventpress .xdata
2976
2976
dy = event .ydata - self ._eventpress .ydata
2977
2977
@@ -2987,9 +2987,10 @@ def _onmove(self, event):
2987
2987
dy *= y_factor
2988
2988
y0 = y1
2989
2989
2990
- # from center
2990
+ # Keeping the center fixed
2991
2991
if 'center' in state :
2992
2992
if 'square' in state :
2993
+ # Force the same change in dx and dy
2993
2994
if self ._active_handle in ['E' , 'W' ]:
2994
2995
# using E, W handle we need to update dy accordingly
2995
2996
dy = dx
@@ -2999,24 +3000,26 @@ def _onmove(self, event):
2999
3000
else :
3000
3001
dx = dy = max (dx , dy , key = abs )
3001
3002
3002
- dw = sizepress [0 ] / 2 + dx
3003
- dh = sizepress [1 ] / 2 + dy
3003
+ # new half-width and half-height
3004
+ hw = size_on_press [0 ] / 2 + dx
3005
+ hh = size_on_press [1 ] / 2 + dy
3004
3006
3005
3007
if 'square' not in state :
3006
3008
# cancel changes in perpendicular direction
3007
3009
if self ._active_handle in ['E' , 'W' ]:
3008
- dh = sizepress [1 ] / 2
3010
+ hh = size_on_press [1 ] / 2
3009
3011
if self ._active_handle in ['N' , 'S' ]:
3010
- dw = sizepress [0 ] / 2
3012
+ hw = size_on_press [0 ] / 2
3011
3013
3012
- x0 , x1 , y0 , y1 = (center [0 ] - dw , center [0 ] + dw ,
3013
- center [1 ] - dh , center [1 ] + dh )
3014
+ x0 , x1 , y0 , y1 = (center [0 ] - hw , center [0 ] + hw ,
3015
+ center [1 ] - hh , center [1 ] + hh )
3014
3016
3015
3017
else :
3018
+ # Keeping the opposite corner/edge fixed
3016
3019
if 'square' in state :
3017
3020
dx = dy = max (dx , dy , key = abs )
3018
- x1 = x0 + x_factor * (dx + sizepress [0 ])
3019
- y1 = y0 + y_factor * (dy + sizepress [1 ])
3021
+ x1 = x0 + x_factor * (dx + size_on_press [0 ])
3022
+ y1 = y0 + y_factor * (dy + size_on_press [1 ])
3020
3023
else :
3021
3024
if self ._active_handle in ['E' , 'W' ] + self ._corner_order :
3022
3025
x1 = event .xdata
0 commit comments