@@ -2970,8 +2970,8 @@ def _onmove(self, event):
29702970 # resize an existing shape
29712971 if self ._active_handle and self ._active_handle != 'C' :
29722972 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 ]
29752975 dx = event .xdata - self ._eventpress .xdata
29762976 dy = event .ydata - self ._eventpress .ydata
29772977
@@ -2987,9 +2987,10 @@ def _onmove(self, event):
29872987 dy *= y_factor
29882988 y0 = y1
29892989
2990- # from center
2990+ # Keeping the center fixed
29912991 if 'center' in state :
29922992 if 'square' in state :
2993+ # Force the same change in dx and dy
29932994 if self ._active_handle in ['E' , 'W' ]:
29942995 # using E, W handle we need to update dy accordingly
29952996 dy = dx
@@ -2999,24 +3000,26 @@ def _onmove(self, event):
29993000 else :
30003001 dx = dy = max (dx , dy , key = abs )
30013002
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
30043006
30053007 if 'square' not in state :
30063008 # cancel changes in perpendicular direction
30073009 if self ._active_handle in ['E' , 'W' ]:
3008- dh = sizepress [1 ] / 2
3010+ hh = size_on_press [1 ] / 2
30093011 if self ._active_handle in ['N' , 'S' ]:
3010- dw = sizepress [0 ] / 2
3012+ hw = size_on_press [0 ] / 2
30113013
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 )
30143016
30153017 else :
3018+ # Keeping the opposite corner/edge fixed
30163019 if 'square' in state :
30173020 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 ])
30203023 else :
30213024 if self ._active_handle in ['E' , 'W' ] + self ._corner_order :
30223025 x1 = event .xdata
0 commit comments