|
11 | 11 | from matplotlib.numerix import npyma as ma |
12 | 12 |
|
13 | 13 | from matplotlib._path import point_in_path, get_path_extents, \ |
14 | | - point_in_path_collection |
15 | | -import matplotlib._path as _path |
| 14 | + point_in_path_collection, get_path_collection_extents, \ |
| 15 | + path_in_path |
16 | 16 | from matplotlib.cbook import simple_linear_interpolation |
17 | 17 |
|
18 | 18 | KAPPA = 4.0 * (npy.sqrt(2) - 1) / 3.0 |
@@ -128,6 +128,30 @@ def __init__(self, vertices, codes=None): |
128 | 128 | self.codes = codes |
129 | 129 | self.vertices = vertices |
130 | 130 |
|
| 131 | + #@staticmethod |
| 132 | + def make_compound_path(*args): |
| 133 | + """ |
| 134 | + Make a compound path from a list of Path objects. Only |
| 135 | + polygons (not curves) are supported. |
| 136 | + """ |
| 137 | + for p in args: |
| 138 | + assert p.codes is None |
| 139 | + |
| 140 | + lengths = [len(x) for x in args] |
| 141 | + total_length = sum(lengths) |
| 142 | + |
| 143 | + vertices = npy.vstack([x.vertices for x in args]) |
| 144 | + vertices.reshape((total_length, 2)) |
| 145 | + |
| 146 | + codes = Path.LINETO * npy.ones(total_length) |
| 147 | + i = 0 |
| 148 | + for length in lengths: |
| 149 | + codes[i] = Path.MOVETO |
| 150 | + i += length |
| 151 | + |
| 152 | + return Path(vertices, codes) |
| 153 | + make_compound_path = staticmethod(make_compound_path) |
| 154 | + |
131 | 155 | def __repr__(self): |
132 | 156 | return "Path(%s, %s)" % (self.vertices, self.codes) |
133 | 157 |
|
@@ -186,9 +210,18 @@ def contains_point(self, point, transform=None): |
186 | 210 | """ |
187 | 211 | if transform is None: |
188 | 212 | from transforms import IdentityTransform |
189 | | - transform = IdentityTransform |
| 213 | + transform = IdentityTransform() |
190 | 214 | return point_in_path(point[0], point[1], self, transform.frozen()) |
191 | 215 |
|
| 216 | + def contains_path(self, path, transform=None): |
| 217 | + """ |
| 218 | + Returns True if this path completely contains the given path. |
| 219 | + """ |
| 220 | + if transform is None: |
| 221 | + from transforms import IdentityTransform |
| 222 | + transform = IdentityTransform() |
| 223 | + return path_in_path(self, IdentityTransform(), path, transform) |
| 224 | + |
192 | 225 | def get_extents(self, transform=None): |
193 | 226 | """ |
194 | 227 | Returns the extents (xmin, ymin, xmax, ymax) of the path. |
@@ -408,8 +441,9 @@ def wedge(cls, theta1, theta2): |
408 | 441 | return cls.arc(theta1, theta2, True) |
409 | 442 | wedge = classmethod(wedge) |
410 | 443 |
|
| 444 | +_get_path_collection_extents = get_path_collection_extents |
411 | 445 | def get_path_collection_extents(*args): |
412 | 446 | from transforms import Bbox |
413 | 447 | if len(args[1]) == 0: |
414 | 448 | raise ValueError("No paths provided") |
415 | | - return Bbox.from_extents(*_path.get_path_collection_extents(*args)) |
| 449 | + return Bbox.from_extents(*_get_path_collection_extents(*args)) |
0 commit comments