Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fe4bda0

Browse files
committed
Better use of transforms
1 parent 2081f7f commit fe4bda0

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

lib/matplotlib/widgets.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ def _get_translate_rotate_transform(self):
23742374
rect = self.to_draw
23752375
x0, y0, width, height, angle = self._rect_properties
23762376
return (transforms.Affine2D()
2377-
.rotate_deg_around(x0, y0, -np.rad2deg(angle))
2377+
.rotate_around(x0, y0, -angle)
23782378
.translate(-x0, -y0))
23792379

23802380
def _press(self, event):
@@ -2555,32 +2555,29 @@ def _rect_properties(self):
25552555
def corners(self):
25562556
"""Corners of rectangle from lower left, moving clockwise."""
25572557
x0, y0, width, height, angle = self._rect_properties
2558-
x = np.array([0, width, width, 0])
2559-
y = np.array([0, 0, height, height])
2560-
xc = x0 + (np.cos(angle) * x - np.sin(angle) * y)
2561-
yc = y0 + (np.sin(angle) * x + np.cos(angle) * y)
2562-
return tuple(xc), tuple(yc)
2558+
xy = np.array([[0, width, width, 0],
2559+
[0, 0, height, height]])
2560+
xyc = self._get_translate_rotate_transform().inverted().transform(xy.T)
2561+
return tuple(xyc[:, 0]), tuple(xyc[:, 1])
25632562

25642563
@property
25652564
def edge_centers(self):
25662565
"""Midpoint of rectangle edges from left, moving anti-clockwise."""
25672566
x0, y0, width, height, angle = self._rect_properties
25682567
w = width / 2.
25692568
h = height / 2.
2570-
x = np.array([0, w, width, w])
2571-
y = np.array([h, 0, h, height])
2572-
xe = x0 + (np.cos(angle) * x - np.sin(angle) * y)
2573-
ye = y0 + (np.sin(angle) * x + np.cos(angle) * y)
2574-
return tuple(xe), tuple(ye)
2569+
xy = np.array([[0, w, width, w],
2570+
[h, 0, h, height]])
2571+
xye = self._get_translate_rotate_transform().inverted().transform(xy.T)
2572+
return tuple(xye[:, 0]), tuple(xye[:, 1])
25752573

25762574
@property
25772575
def center(self):
25782576
"""Center of rectangle."""
25792577
x0, y0, width, height, angle = self._rect_properties
2580-
hw, hh = width / 2, height / 2
2581-
dx = np.cos(angle) * hw - np.sin(angle) * hh
2582-
dy = np.sin(angle) * hw + np.cos(angle) * hh
2583-
return x0 + dx, y0 + dy
2578+
xy = np.array([width / 2, height / 2])
2579+
xyc = self._get_translate_rotate_transform().inverted().transform(xy)
2580+
return tuple(xyc)
25842581

25852582
@property
25862583
def extents(self):

0 commit comments

Comments
 (0)