8000 Fixed __array__ releated bug that I introduced. · cirosantilli/matplotlib@e9cc98e · GitHub
[go: up one dir, main page]

Skip to content

Commit e9cc98e

Browse files
Phil Elsonpelson
authored andcommitted
Fixed __array__ releated bug that I introduced.
1 parent 1b1b340 commit e9cc98e

File tree

3 files changed

+52
-33
lines changed

3 files changed

+52
-33
lines changed

lib/matplotlib/collections.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,6 @@ def draw(self, renderer):
242242
self._set_gc_clip(gc)
243243
gc.set_snap(self.get_snap())
244244

245-
if self._hatch:
246-
gc.set_hatch(self._hatch)
247-
248-
# XXX INVESTIGATE.
249-
print('transOffset: ', transOffset)
250-
print(transOffset.is_affine, transOffset.get_matrix())
251-
mtx = transOffset.get_matrix()
252-
import matplotlib.transforms as mtransforms
253-
transOffset = mtransforms.Affine2D()
254-
transOffset.set_matrix(mtx)
255-
# XXX end investigate
256-
257245
renderer.draw_path_collection(
258246
gc, transform.frozen(), paths, self.get_transforms(),
259247
offsets, transOffset, self.get_facecolor(), self.get_edgecolor(),

lib/matplotlib/transforms.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import cbook
4747
from path import Path
4848

49-
DEBUG = True
49+
DEBUG = False
5050
if DEBUG:
5151
import warnings
5252

@@ -113,11 +113,14 @@ def _invalidate_internal(self, value, invalidating_node):
113113
Called by :meth:`invalidate` and subsequently ascends the transform
114114
stack calling each TransformNode's _invalidate_internal method.
115115
"""
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.
121124
status_changed = self._invalid < value
122125

123126
if self.pass_through or status_changed:
@@ -1067,9 +1070,13 @@ def __radd__(self, other):
10671070

10681071
def __array__(self, *args, **kwargs):
10691072
"""
1070-
Used by C/C++ -based backends to get at the array matrix data.
1073+
Array interface to get at this Transform's matrix.
10711074
"""
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.')
10731080

10741081
def transform(self, values):
10751082
"""
@@ -1340,6 +1347,7 @@ def __init__(self):
13401347
self._inverted = None
13411348

13421349
def __array__(self, *args, **kwargs):
1350+
# optimises the access of the transform matrix vs the superclass
13431351
return self.get_matrix()
13441352

13451353
@staticmethod
@@ -1402,9 +1410,6 @@ def _get_is_separable(self):
14021410
return mtx[0, 1] == 0.0 and mtx[1, 0] == 0.0
14031411
is_separable = property(_get_is_separable)
14041412

1405-
def __array__(self, *args, **kwargs):
1406-
return self.get_matrix()
1407-
14081413
def to_values(self):
14091414
"""
14101415
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):
19241929
# (b) it is the left hand node which has triggered the invalidation
19251930
if value == Transform.INVALID_AFFINE \
19261931
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):
19281933

19291934
value = Transform.INVALID
19301935

1931-
Transform._invalidate_internal(self, value=value, invalidating_node=invalidating_node)
1936+
Transform._invalidate_internal(self, value=value,
1937+
invalidating_node=invalidating_node)
19321938

19331939
def _get_is_affine(self):
19341940
return self._a.is_affine and self._b.is_affine
@@ -2048,10 +2054,10 @@ def composite_transform_factory(a, b):
20482054
20492055
c = a + b
20502056
"""
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.
20552061
if isinstance(a, IdentityTransform):
20562062
return b
20572063
elif isinstance(b, IdentityTransform):

src/agg_py_transforms.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,45 @@
99
#include "agg_trans_affine.h"
1010

1111
/** A helper function to convert from a Numpy affine transformation matrix
12-
* to an agg::trans_affine.
12+
* to an agg::trans_affine. If errors = false then an Identity transform is returned.
1313
*/
1414
agg::trans_affine
1515
py_to_agg_transformation_matrix(PyObject* obj, bool errors = true)
1616
{
1717
PyArrayObject* matrix = NULL;
1818

19+
/** If None either raise a TypeError or return an agg identity transform. */
20+
if (obj == Py_None)
21+
{
22+
if (errors)
23+
{
24+
throw Py::TypeError("Cannot convert None to an affine transform.");
25+
}
26+
27+
return agg::trans_affine();
28+
}
29+
30+
/** Try turning the object into an affine transform matrix. */
1931
try
2032
{
21-
if (obj == Py_None)
22-
throw std::exception();
2333
matrix = (PyArrayObject*) PyArray_FromObject(obj, PyArray_DOUBLE, 2, 2);
2434
if (!matrix)
2535
throw std::exception();
36+
}
37+
catch (...)
38+
{
39+
Py_XDECREF(matrix);
40+
if (errors)
41+
{
42+
throw Py::TypeError("Unable to get an affine transform matrix from the given object.");
43+
}
44+
45+
return agg::trans_affine();
46+
}
47+
48+
/** Try turning the matrix into an agg transform. */
49+
try
50+
{
2651
if (PyArray_NDIM(matrix) == 2 || PyArray_DIM(matrix, 0) == 3 || PyArray_DIM(matrix, 1) == 3)
2752
{
2853
size_t stride0 = PyArray_STRIDE(matrix, 0);
@@ -54,7 +79,7 @@ py_to_agg_transformation_matrix(PyObject* obj, bool errors = true)
5479
if (errors)
5580
{
5681
Py_XDECREF(matrix);
57-
throw Py::TypeError("Invalid affine transformation matrix");
82+
throw Py::TypeError("Invalid affine transformation matrix.");
5883
}
5984
}
6085

0 commit comments

Comments
 (0)
0