@@ -92,9 +92,12 @@ class TransformNode:
92
92
# Invalidation may affect only the affine part. If the
93
93
# invalidation was "affine-only", the _invalid member is set to
94
94
# INVALID_AFFINE_ONLY
95
- INVALID_NON_AFFINE = 1
96
- INVALID_AFFINE = 2
97
- INVALID = INVALID_NON_AFFINE | INVALID_AFFINE
95
+ INVALID_NON_AFFINE = _api .deprecated ("3.8" )(_api .classproperty (lambda cls : 1 ))
96
+ INVALID_AFFINE = _api .deprecated ("3.8" )(_api .classproperty (lambda cls : 2 ))
97
+ INVALID = _api .deprecated ("3.8" )(_api .classproperty (lambda cls : 3 ))
98
+
99
+ # Possible values for the _invalid attribute.
100
+ _VALID , _INVALID_AFFINE_ONLY , _INVALID_FULL = range (3 )
98
101
99
102
# Some metadata about the transform, used to determine whether an
100
103
# invalidation is affine-only
@@ -117,10 +120,9 @@ def __init__(self, shorthand_name=None):
117
120
``str(transform)`` when DEBUG=True.
118
121
"""
119
122
self ._parents = {}
120
-
121
123
# TransformNodes start out as invalid until their values are
122
124
# computed for the first time.
123
- self ._invalid = 1
125
+ self ._invalid = self . _INVALID_FULL
124
126
self ._shorthand_name = shorthand_name or ''
125
127
126
128
if DEBUG :
@@ -159,37 +161,24 @@ def invalidate(self):
159
161
Invalidate this `TransformNode` and triggers an invalidation of its
160
162
ancestors. Should be called any time the transform changes.
161
163
"""
162
- value = self .INVALID
163
- if self .is_affine :
164
- value = self .INVALID_AFFINE
165
- return self ._invalidate_internal (value , invalidating_node = self )
164
+ return self ._invalidate_internal (
165
+ level = self ._INVALID_AFFINE_ONLY if self .is_affine else self ._INVALID_FULL ,
166
+ invalidating_node = self )
166
167
167
- def _invalidate_internal (self , value , invalidating_node ):
168
+ def _invalidate_internal (self , level , invalidating_node ):
168
169
"""
169
170
Called by :meth:`invalidate` and subsequently ascends the transform
170
171
stack calling each TransformNode's _invalidate_internal method.
171
172
"""
172
- # determine if this call will be an extension to the invalidation
173
- # status. If not, then a shortcut means that we needn't invoke an
174
- # invalidation up the transform stack as it will already have been
175
- # invalidated.
176
-
177
- # N.B This makes the invalidation sticky, once a transform has been
178
- # invalidated as NON_AFFINE, then it will always be invalidated as
179
- # NON_AFFINE even when triggered with a AFFINE_ONLY invalidation.
180
- # In most cases this is not a problem (i.e. for interactive panning and
181
- # zooming) and the only side effect will be on performance.
182
- status_changed = self ._invalid < value
183
-
184
- if self .pass_through or status_changed :
185
- self ._invalid = value
186
-
187
- for parent in list (self ._parents .values ()):
188
- # Dereference the weak reference
189
- parent = parent ()
190
- if parent is not None :
191
- parent ._invalidate_internal (
192
- value = value , invalidating_node = self )
173
+ # If we are already more invalid than the currently propagated invalidation,
174
+ # then we don't need to do anything.
175
+ if level <= self ._invalid and not self .pass_through :
176
+ return
177
+ self ._invalid = level
178
+ for parent in list (self ._parents .values ()):
179
+ parent = parent () # Dereference the weak reference.
180
+ if parent is not None :
181
+ parent ._invalidate_internal (level = level , invalidating_node = self )
193
182
194
183
def set_children (self , * children ):
195
184
"""
@@ -2379,20 +2368,17 @@ def frozen(self):
2379
2368
return frozen .frozen ()
2380
2369
return frozen
2381
2370
2382
- def _invalidate_internal (self , value , invalidating_node ):
2371
+ def _invalidate_internal (self , level , invalidating_node ):
2383
2372
# In some cases for a composite transform, an invalidating call to
2384
2373
# AFFINE_ONLY needs to be extended to invalidate the NON_AFFINE part
2385
2374
# too. These cases are when the right hand transform is non-affine and
2386
2375
# either:
2387
2376
# (a) the left hand transform is non affine
2388
2377
# (b) it is the left hand node which has triggered the invalidation
2389
- if (value == Transform .INVALID_AFFINE and
2390
- not self ._b .is_affine and
2378
+ if (not self ._b .is_affine and
2391
2379
(not self ._a .is_affine or invalidating_node is self ._a )):
2392
- value = Transform .INVALID
2393
-
2394
- super ()._invalidate_internal (value = value ,
2395
- invalidating_node = invalidating_node )
2380
+ level = Transform ._INVALID_FULL
2381
+ super ()._invalidate_internal (level , invalidating_node )
2396
2382
2397
2383
def __eq__ (self , other ):
2398
2384
if isinstance (other , (CompositeGenericTransform , CompositeAffine2D )):
@@ -2757,7 +2743,7 @@ def __init__(self, path, transform):
2757
2743
def _revalidate (self ):
2758
2744
# only recompute if the invalidation includes the non_affine part of
2759
2745
# the transform
2760
- if (self ._invalid & self . INVALID_NON_AFFINE == self .INVALID_NON_AFFINE
2746
+ if (self ._invalid == self ._INVALID_FULL
2761
2747
or self ._transformed_path is None ):
2762
2748
self ._transformed_path = \
2763
2749
self ._transform .transform_path_non_affine (self ._path )
0 commit comments