@@ -56,6 +56,11 @@ class Path(object):
5656 :class:`Path` objects, as an optimization, do not store a *codes*
5757 at all, but have a default one provided for them by
5858 :meth:`iter_segments`.
59+
60+ Note also that the vertices and codes arrays should be treated as
61+ immutable -- there are a number of optimizations and assumptions
62+ made up front in the constructor that will not change when the
63+ data changes.
5964 """
6065
6166 # Path codes
@@ -84,46 +89,29 @@ def __init__(self, vertices, codes=None):
8489 dimension.
8590
8691 If *codes* is None, *vertices* will be treated as a series of
87- line segments. If *vertices* contains masked values, the
88- resulting path will be compressed, with ``MOVETO`` codes
89- inserted in the correct places to jump over the masked
90- regions.
92+ line segments.
93+
94+ If *vertices* contains masked values, they will be converted
95+ to NaNs which are then handled correctly by the Agg
96+ PathIterator and other consumers of path data, such as
97+ :meth:`iter_segments`.
9198 """
9299 if ma .isMaskedArray (vertices ):
93- is_mask = True
94- mask = ma .getmask (vertices )
100+ vertices = vertices .astype (np .float_ ).filled (np .nan )
95101 else :
96- is_mask = False
97102 vertices = np .asarray (vertices , np .float_ )
98- mask = ma .nomask
99103
100104 if codes is not None :
101105 codes = np .asarray (codes , self .code_type )
102106 assert codes .ndim == 1
103107 assert len (codes ) == len (vertices )
104108
105- # The path being passed in may have masked values. However,
106- # the backends (and any affine transformations in matplotlib
107- # itself), are not expected to deal with masked arrays, so we
108- # must remove them from the array (using compressed), and add
109- # MOVETO commands to the codes array accordingly.
110- if is_mask :
111- if mask is not ma .nomask :
112- mask1d = np .logical_or .reduce (mask , axis = 1 )
113- gmask1d = np .invert (mask1d )
114- if codes is None :
115- codes = np .empty ((len (vertices )), self .code_type )
116- codes .fill (self .LINETO )
117- codes [0 ] = self .MOVETO
118- vertices = vertices [gmask1d ].filled () # ndarray
119- codes [np .roll (mask1d , 1 )] = self .MOVETO
120- codes = codes [gmask1d ] # np.compress is much slower
121- else :
122- vertices = np .asarray (vertices , np .float_ )
123-
124109 assert vertices .ndim == 2
125110 assert vertices .shape [1 ] == 2
126111
112+ self .should_simplify = (codes is None and
113+ np .all (np .isfinite (vertices )) and
114+ len (vertices ) >= 128 )
127115 self .codes = codes
128116 self .vertices = vertices
129117
0 commit comments