10000 Merge pull request #22108 from anntzer/fr · matplotlib/matplotlib@45de25e · GitHub
[go: up one dir, main page]

Skip to content

Commit 45de25e

Browse files
authored
Merge pull request #22108 from anntzer/fr
Micro-optimize rotation transform.
2 parents 14a94c3 + ff120cd commit 45de25e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/matplotlib/transforms.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,9 +2002,16 @@ def rotate(self, theta):
20022002
"""
20032003
a = math.cos(theta)
20042004
b = math.sin(theta)
2005-
rotate_mtx = np.array([[a, -b, 0.0], [b, a, 0.0], [0.0, 0.0, 1.0]],
2006-
float)
2007-
self._mtx = np.dot(rotate_mtx, self._mtx)
2005+
mtx = self._mtx
2006+
# Operating and assigning one scalar at a time is much faster.
2007+
(xx, xy, x0), (yx, yy, y0), _ = mtx.tolist()
2008+
# mtx = [[a -b 0], [b a 0], [0 0 1]] * mtx
2009+
mtx[0, 0] = a * xx - b * yx
2010+
mtx[0, 1] = a * xy - b * yy
2011+
mtx[0, 2] = a * x0 - b * y0
2012+
mtx[1, 0] = b * xx + a * yx
2013+
mtx[1, 1] = b * xy + a * yy
2014+
mtx[1, 2] = b * x0 + a * y0
20082015
self.invalidate()
20092016
return self
20102017

0 commit comments

Comments
 (0)
0