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

Skip to content

Commit abc4111

Browse files
committed
Better use of transforms
1 parent d8ed099 commit abc4111

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
@@ -2373,7 +2373,7 @@ def _get_translate_rotate_transform(self):
23732373
rect = self.to_draw
23742374
x0, y0, width, height, angle = self._rect_properties
23752375
return (transforms.Affine2D()
2376-
.rotate_deg_around(x0, y0, -np.rad2deg(angle))
2376+
.rotate_around(x0, y0, -angle)
23772377
.translate(-x0, -y0))
23782378

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

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

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

25842581
@property
25852582
def extents(self):

0 commit comments

Comments
 (0)