|
46 | 46 | import cbook |
47 | 47 | from path import Path |
48 | 48 |
|
49 | | -DEBUG = True |
| 49 | +DEBUG = False |
50 | 50 | if DEBUG: |
51 | 51 | import warnings |
52 | 52 |
|
@@ -113,11 +113,14 @@ def _invalidate_internal(self, value, invalidating_node): |
113 | 113 | Called by :meth:`invalidate` and subsequently ascends the transform |
114 | 114 | stack calling each TransformNode's _invalidate_internal method. |
115 | 115 | """ |
116 | | - # determine if this call will be an extension to the invalidation status |
117 | | - # if not, then a shortcut means that we needn't invoke an invalidation |
118 | | - # up the transform stack |
119 | | - # XXX This makes the invalidation sticky, once a transform has been invalidated as NON_AFFINE |
120 | | - # too, then it is always NON_AFFINE invalid, even when triggered with a AFFINE_ONLY invalidation. |
| 116 | + # determine if this call will be an extension to the invalidation |
| 117 | + # status if not, then a shortcut means that we needn't invoke an |
| 118 | + # invalidation up the transform stack |
| 119 | + # N.B This makes the invalidation sticky, once a transform has been |
| 120 | + # invalidated as NON_AFFINE too, then it is always NON_AFFINE invalid, |
| 121 | + # even when triggered with a AFFINE_ONLY invalidation. This will not |
| 122 | + # be experienced, as in most cases the invalidation will by AFFINE_ONLY |
| 123 | + # anyway. |
121 | 124 | status_changed = self._invalid < value |
122 | 125 |
|
123 | 126 | if self.pass_through or status_changed: |
@@ -1067,9 +1070,13 @@ def __radd__(self, other): |
1067 | 1070 |
|
1068 | 1071 | def __array__(self, *args, **kwargs): |
1069 | 1072 | """ |
1070 | | - Used by C/C++ -based backends to get at the array matrix data. |
| 1073 | + Array interface to get at this Transform's matrix. |
1071 | 1074 | """ |
1072 | | - raise NotImplementedError |
| 1075 | + # note, this method is also used by C/C++ -based backends |
| 1076 | + if self.is_affine: |
| 1077 | + return self.get_matrix() |
| 1078 | + else: |
| 1079 | + raise ValueError('Cannot convert this transform to an array.') |
1073 | 1080 |
|
1074 | 1081 | def transform(self, values): |
1075 | 1082 | """ |
@@ -1340,6 +1347,7 @@ def __init__(self): |
1340 | 1347 | self._inverted = None |
1341 | 1348 |
|
1342 | 1349 | def __array__(self, *args, **kwargs): |
| 1350 | + # optimises the access of the transform matrix vs the superclass |
1343 | 1351 | return self.get_matrix() |
1344 | 1352 |
|
1345 | 1353 | @staticmethod |
@@ -1402,9 +1410,6 @@ def _get_is_separable(self): |
1402 | 1410 | return mtx[0, 1] == 0.0 and mtx[1, 0] == 0.0 |
1403 | 1411 | is_separable = property(_get_is_separable) |
1404 | 1412 |
|
1405 | | - def __array__(self, *args, **kwargs): |
1406 | | - return self.get_matrix() |
1407 | | - |
1408 | 1413 | def to_values(self): |
1409 | 1414 | """ |
1410 | 1415 | Return the values of the matrix as a sequence (a,b,c,d,e,f) |
@@ -1924,11 +1929,12 @@ def _invalidate_internal(self, value, invalidating_node): |
1924 | 1929 | # (b) it is the left hand node which has triggered the invalidation |
1925 | 1930 | if value == Transform.INVALID_AFFINE \ |
1926 | 1931 | and not self._b.is_affine \ |
1927 | | - and (not self._a.is_affine or invalidating_node is self._a): # note use of is will break when using TransformWrapper |
| 1932 | + and (not self._a.is_affine or invalidating_node is self._a): |
1928 | 1933 |
|
1929 | 1934 | value = Transform.INVALID |
1930 | 1935 |
|
1931 | | - Transform._invalidate_internal(self, value=value, invalidating_node=invalidating_node) |
| 1936 | + Transform._invalidate_internal(self, value=value, |
| 1937 | + invalidating_node=invalidating_node) |
1932 | 1938 |
|
1933 | 1939 | def _get_is_affine(self): |
1934 | 1940 | return self._a.is_affine and self._b.is_affine |
@@ -2048,10 +2054,10 @@ def composite_transform_factory(a, b): |
2048 | 2054 |
|
2049 | 2055 | c = a + b |
2050 | 2056 | """ |
2051 | | - # check to see if any of a or b are IdentityTransforms. Note we |
2052 | | - # do not use equality here since we may have wrapped transforms |
2053 | | - # which are currently equal to Identity, but since wrapped transforms |
2054 | | - # are mutable, they may not always be equal. |
| 2057 | + # check to see if any of a or b are IdentityTransforms. We use |
| 2058 | + # isinstance here to guarantee that the transforms will *always* |
| 2059 | + # be IdentityTransforms. Since TransformWrappers are mutable, |
| 2060 | + # use of equality here would be wrong. |
2055 | 2061 | if isinstance(a, IdentityTransform): |
2056 | 2062 | return b |
2057 | 2063 | elif isinstance(b, IdentityTransform): |
|
0 commit comments