@@ -1971,7 +1971,7 @@ def set_matrix(self, mtx):
1971
1971
1972
1972
.
1973
1973
"""
1974
- self ._mtx = mtx
1974
+ self ._mtx = _eigen . Affine2d ( mtx )
1975
1975
self .invalidate ()
1976
1976
1977
1977
def set (self , other ):
@@ -1980,15 +1980,14 @@ def set(self, other):
1980
1980
`Affine2DBase` object.
1981
1981
"""
1982
1982
_api .check_isinstance (Affine2DBase , other = other )
1983
- self ._mtx = other .get_matrix ()
1983
+ self ._mtx = _eigen . Affine2d ( other .get_matrix () )
1984
1984
self .invalidate ()
1985
1985
1986
1986
def clear (self ):
1987
1987
"""
1988
1988
Reset the underlying matrix to the identity transform.
1989
1989
"""
1990
- # A bit faster than np.identity(3).
1991
- self ._mtx = IdentityTransform ._mtx .copy ()
1990
+ self ._mtx .reset ()
1992
1991
self .invalidate ()
1993
1992
return self
1994
1993
@@ -2000,18 +1999,7 @@ def rotate(self, theta):
2000
1999
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
2001
2000
and :meth:`scale`.
2002
2001
"""
2003
- a = math .cos (theta )
2004
- b = math .sin (theta )
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
2002
+ self ._mtx .rotate (theta )
2015
2003
self .invalidate ()
2016
2004
return self
2017
2005
@@ -2055,8 +2043,7 @@ def translate(self, tx, ty):
2055
2043
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
2056
2044
and :meth:`scale`.
2057
2045
"""
2058
- self ._mtx [0 , 2 ] += tx
2059
- self ._mtx [1 , 2 ] += ty
2046
+ self ._mtx .translate (tx , ty )
2060
2047
self .invalidate ()
2061
2048
return self
2062
2049
@@ -2073,13 +2060,7 @@ def scale(self, sx, sy=None):
2073
2060
"""
2074
2061
if sy is None :
2075
2062
sy = sx
2076
- # explicit element-wise scaling is fastest
2077
- self ._mtx [0 , 0 ] *= sx
2078
- self ._mtx [0 , 1 ] *= sx
2079
- self ._mtx [0 , 2 ] *= sx
2080
- self ._mtx [1 , 0 ] *= sy
2081
- self ._mtx [1 , 1 ] *= sy
2082
- self ._mtx [1 , 2 ] *= sy
2063
+ self ._mtx .scale (sx , sy )
2083
2064
self .invalidate ()
2084
2065
return self
2085
2066
@@ -2094,18 +2075,7 @@ def skew(self, xShear, yShear):
2094
2075
calls to :meth:`rotate`, :meth:`rotate_deg`, :meth:`translate`
2095
2076
and :meth:`scale`.
2096
2077
"""
2097
- rx = math .tan (xShear )
2098
- ry = math .tan (yShear )
2099
- mtx = self ._mtx
2100
- # Operating and assigning one scalar at a time is much faster.
2101
- (xx , xy , x0 ), (yx , yy , y0 ), _ = mtx .tolist ()
2102
- # mtx = [[1 rx 0], [ry 1 0], [0 0 1]] * mtx
2103
- mtx [0 , 0 ] += rx * yx
2104
- mtx [0 , 1 ] += rx * yy
2105
- mtx [0 , 2 ] += rx * y0
2106
- mtx [1 , 0 ] += ry * xx
2107
- mtx [1 , 1 ] += ry * xy
2108
- mtx [1 , 2 ] += ry * x0
2078
+ self ._mtx .skew (xShear , yShear )
2109
2079
self .invalidate ()
2110
2080
return self
2111
2081
@@ -2128,7 +2098,7 @@ class IdentityTransform(Affine2DBase):
2128
2098
A special class that does one thing, the identity transform, in a
2129
2099
fast way.
2130
2100
"""
2131
- _mtx = np . identity ( 3 )
2101
+ _mtx = _eigen . Affine2d ( )
2132
2102
2133
2103
def frozen (self ):
2134
2104
# docstring inherited
@@ -2138,7 +2108,7 @@ def frozen(self):
2138
2108
2139
2109
def get_matrix (self ):
2140
2110
# docstring inherited
2141
- return self ._mtx
2111
+ return self ._mtx . get_matrix ()
2142
2112
2143
2113
def transform (self , values ):
2144
2114
# docstring inherited
@@ -2325,16 +2295,16 @@ def get_matrix(self):
2325
2295
# docstring inherited
2326
2296
if self ._invalid :
2327
2297
if self ._x == self ._y :
2328
- self ._mtx = self ._x .get_matrix ()
2298
+ self ._mtx = _eigen . Affine2d ( self ._x .get_matrix () )
2329
2299
else :
2330
2300
x_mtx = self ._x .get_matrix ()
2331
2301
y_mtx = self ._y .get_matrix ()
2332
2302
# We already know the transforms are separable, so we can skip
2333
2303
# setting b and c to zero.
2334
- self ._mtx = np . array ([x_mtx [0 ], y_mtx [1 ], [0.0 , 0.0 , 1.0 ]])
2304
+ self ._mtx = _eigen . Affine2d ([x_mtx [0 ], y_mtx [1 ], [0.0 , 0.0 , 1.0 ]])
2335
2305
self ._inverted = None
2336
2306
self ._invalid = 0
2337
- return self ._mtx
2307
+ return self ._mtx . get_matrix ()
2338
2308
2339
2309
2340
2310
def blended_transform_factory (x_transform , y_transform ):
@@ -2510,12 +2480,10 @@ def _iter_break_from_left_to_right(self):
2510
2480
def get_matrix (self ):
2511
2481
# docstring inherited
2512
2482
if self ._invalid :
2513
- self ._mtx = np .dot (
2514
- self ._b .get_matrix (),
2515
- self ._a .get_matrix ())
2483
+ self ._mtx = self ._b ._mtx @ self ._a ._mtx
2516
2484
self ._inverted = None
2517
2485
self ._invalid = 0
2518
- return self ._mtx
2486
+ return self ._mtx . get_matrix ()
2519
2487
2520
2488
2521
2489
def composite_transform_factory (a , b ):
@@ -2578,13 +2546,14 @@ def get_matrix(self):
2578
2546
if DEBUG and (x_scale == 0 or y_scale == 0 ):
2579
2547
raise ValueError (
2580
2548
"Transforming from or to a singular bounding box" )
2581
- self ._mtx = np .array ([[x_scale , 0.0 , - inl * x_scale + outl ],
2582
- [ 0.0 , y_scale , - inb * y_scale + outb ],
2583
- [ 0.0 , 0.0 , 1.0 ]],
2584
- float )
2549
+ self ._mtx = _eigen .Affine2d ([
2550
+ [x_scale , 0.0 , - inl * x_scale + outl ],
2551
+ [ 0.0 , y_scale , - inb * y_scale + outb ],
2552
+ [ 0.0 , 0.0 , 1.0 ],
2553
+ ])
2585
2554
self ._inverted = None
2586
2555
self ._invalid = 0
2587
- return self ._mtx
2556
+ return self ._mtx . get_matrix ()
2588
2557
2589
2558
2590
2559
class BboxTransformTo (Affine2DBase ):
@@ -2616,13 +2585,14 @@ def get_matrix(self):
2616
2585
outl , outb , outw , outh = self ._boxout .bounds
2617
2586
if DEBUG and (outw == 0 or outh == 0 ):
2618
2587
raise ValueError ("Transforming to a singular bounding box." )
2619
- self ._mtx = np .array ([[outw , 0.0 , outl ],
2620
- [ 0.0 , outh , outb ],
2621
- [ 0.0 , 0.0 , 1.0 ]],
2622
- float )
2588
+ self ._mtx = _eigen .Affine2d ([
2589
+ [outw , 0.0 , outl ],
2590
+ [ 0.0 , outh , outb ],
2591
+ [ 0.0 , 0.0 , 1.0 ],
2592
+ ])
2623
2593
self ._inverted = None
2624
2594
self ._invalid = 0
2625
- return self ._mtx
2595
+ return self ._mtx . get_matrix ()
2626
2596
2627
2597
2628
2598
class BboxTransformFrom (Affine2DBase ):
@@ -2651,13 +2621,14 @@ def get_matrix(self):
2651
2621
raise ValueError ("Transforming from a singular bounding box." )
2652
2622
x_scale = 1.0 / inw
2653
2623
y_scale = 1.0 / inh
2654
- self ._mtx = np .array ([[x_scale , 0.0 , - inl * x_scale ],
2655
- [ 0.0 , y_scale , - inb * y_scale ],
2656
- [ 0.0 , 0.0 , 1.0 ]],
2657
- float )
2624
+ self ._mtx = _eigen .Affine2d ([
2625
+ [x_scale , 0.0 , - inl * x_scale ],
2626
+ [ 0.0 , y_scale , - inb * y_scale ],
2627
+ [ 0.0 , 0.0 , 1.0 ],
2628
+ ])
2658
2629
self ._inverted = None
2659
2630
self ._invalid = 0
2660
- return self ._mtx
2631
+ return self ._mtx . get_matrix ()
2661
2632
2662
2633
2663
2634
class ScaledTranslation (Affine2DBase ):
@@ -2679,10 +2650,10 @@ def get_matrix(self):
2679
2650
# docstring inherited
2680
2651
if self ._invalid :
2681
2652
self ._mtx = _eigen .Affine2d ()
2682
- self ._mtx [: 2 , 2 ] = self ._scale_trans .transform (self ._t )
2653
+ self ._mtx . translate ( * self ._scale_trans .transform (self ._t ) )
2683
2654
self ._invalid = 0
2684
2655
self ._inverted = None
2685
- return self ._mtx
2656
+ return self ._mtx . get_matrix ()
2686
2657
2687
2658
2688
2659
class _ScaledRotation (Affine2DBase ):
@@ -2732,9 +2703,9 @@ def __init__(self, transform, **kwargs):
2732
2703
2733
2704
def get_matrix (self ):
2734
2705
if self ._invalid :
2735
- self ._mtx = self ._base_transform .get_matrix (). copy ( )
2736
- self ._mtx [: 2 , - 1 ] = 0
2737
- return self ._mtx
2706
+ self ._mtx = _eigen . Affine2d ( self ._base_transform .get_matrix ())
2707
+ self ._mtx . remove_translate ()
2708
+ return self ._mtx . get_matrix ()
2738
2709
2739
2710
2740
2711
class TransformedPath (TransformNode ):
0 commit comments