@@ -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,8 @@ def __init__(self, shorthand_name=None):
117
120
``str(transform)`` when DEBUG=True.
118
121
"""
119
122
self ._parents = {}
120
-
121
- # TransformNodes start out as invalid until their values are
122
- # computed for the first time.
123
- self ._invalid = 1
123
+ # Initially invalid, until first computation.
124
+ self ._invalid = self ._INVALID_FULL
124
125
self ._shorthand_name = shorthand_name or ''
125
126
126
127
if DEBUG :
@@ -159,37 +160,24 @@ def invalidate(self):
159
160
Invalidate this `TransformNode` and triggers an invalidation of its
160
161
ancestors. Should be called any time the transform changes.
161
162
"""
162
- value = self .INVALID
163
- if self .is_affine :
164
- value = self .INVALID_AFFINE
165
- return self ._invalidate_internal (value , invalidating_node = self )
163
+ return self ._invalidate_internal (
164
+ level = self ._INVALID_AFFINE_ONLY if self .is_affine else self ._INVALID_FULL ,
165
+ invalidating_node = self )
166
166
167
- def _invalidate_internal (self , value , invalidating_node ):
167
+ def _invalidate_internal (self , level , invalidating_node ):
168
168
"""
169
169
Called by :meth:`invalidate` and subsequently ascends the transform
170
170
stack calling each TransformNode's _invalidate_internal method.
171
171
"""
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 )
172
+ # If we are already more invalid than the currently propagated invalidation,
173
+ # then we don't need to do anything.
174
+ if level <= self ._invalid and not self .pass_through :
175
+ return
176
+ self ._invalid = level
177
+ for parent in list (self ._parents .values ()):
178
+ parent = parent () # Dereference the weak reference.
179
+ if parent is not None :
180
+ parent ._invalidate_internal (level = level , invalidating_node = self )
193
181
194
182
def set_children (self , * children ):
195
183
"""
@@ -2379,20 +2367,17 @@ def frozen(self):
2379
2367
return frozen .frozen ()
2380
2368
return frozen
2381
2369
2382
- def _invalidate_internal (self , value , invalidating_node ):
2370
+ def _invalidate_internal (self , level , invalidating_node ):
2383
2371
# In some cases for a composite transform, an invalidating call to
2384
2372
# AFFINE_ONLY needs to be extended to invalidate the NON_AFFINE part
2385
2373
# too. These cases are when the right hand transform is non-affine and
2386
2374
# either:
2387
2375
# (a) the left hand transform is non affine
2388
2376
# (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
2377
+ if (not self ._b .is_affine and
2391
2378
(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 )
2379
+ level = Transform ._INVALID_FULL
2380
+ super ()._invalidate_internal (level , invalidating_node )
2396
2381
2397
2382
def __eq__ (self , other ):
2398
2383
if isinstance (other , (CompositeGenericTransform , CompositeAffine2D )):
@@ -2757,7 +2742,7 @@ def __init__(self, path, transform):
2757
2742
def _revalidate (self ):
2758
2743
# only recompute if the invalidation includes the non_affine part of
2759
2744
# the transform
2760
- if (self ._invalid & self . INVALID_NON_AFFINE == self .INVALID_NON_AFFINE
2745
+ if (self ._invalid == self ._INVALID_FULL
2761
2746
or self ._transformed_path is None ):
2762
2747
self ._transformed_path = \
2763
2748
self ._transform .transform_path_non_affine (self ._path )
0 commit comments