Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7b9547e

Browse filesBrowse files
committed
Support make_compound_path concatenating only empty paths.
Previously `codes[i]` would fail if codes (i.e. the concatenated path) had length zero.
1 parent 22d036e commit 7b9547e
Copy full SHA for 7b9547e

File tree

2 files changed

+19
-17
lines changed
Filter options

2 files changed

+19
-17
lines changed

‎lib/matplotlib/path.py

Copy file name to clipboardExpand all lines: lib/matplotlib/path.py
+11-15Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -318,29 +318,25 @@ def make_compound_path_from_polys(cls, XY):
318318

319319
@classmethod
320320
def make_compound_path(cls, *args):
321+
r"""
322+
Concatenate a list of `Path`\s into a single `.Path`, removing all `.STOP`\s.
321323
"""
322-
Make a compound path from a list of `Path` objects. Blindly removes
323-
all `Path.STOP` control points.
324-
"""
325-
# Handle an empty list in args (i.e. no args).
326324
if not args:
327325
return Path(np.empty([0, 2], dtype=np.float32))
328-
vertices = np.concatenate([x.vertices for x in args])
326+
vertices = np.concatenate([path.vertices for path in args])
329327
codes = np.empty(len(vertices), dtype=cls.code_type)
330328
i = 0
331329
for path in args:
330+
size = len(path.vertices)
332331
if path.codes is None:
333-
codes[i] = cls.MOVETO
334-
codes[i + 1:i + len(path.vertices)] = cls.LINETO
332+
if size:
333+
codes[i] = cls.MOVETO
334+
codes[i+1:i+size] = cls.LINETO
335335
else:
336-
codes[i:i + len(path.codes)] = path.codes
337-
i += len(path.vertices)
338-
# remove STOP's, since internal STOPs are a bug
339-
not_stop_mask = codes != cls.STOP
340-
vertices = vertices[not_stop_mask, :]
341-
codes = codes[not_stop_mask]
342-
343-
return cls(vertices, codes)
336+
codes[i:i+size] = path.codes
337+
i += size
338+
not_stop_mask = codes != cls.STOP # Remove STOPs, as internal STOPs are a bug.
339+
return cls(vertices[not_stop_mask], codes[not_stop_mask])
344340

345341
def __repr__(self):
346342
return f"Path({self.vertices!r}, {self.codes!r})"

‎lib/matplotlib/tests/test_path.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_path.py
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,14 @@ def test_log_transform_with_zero():
203203
def test_make_compound_path_empty():
204204
# We should be able to make a compound path with no arguments.
205205
# This makes it easier to write generic path based code.
206-
r = Path.make_compound_path()
207-
assert r.vertices.shape == (0, 2)
206+
empty = Path.make_compound_path()
207+
assert empty.vertices.shape == (0, 2)
208+
r2 = Path.make_compound_path(empty, empty)
209+
assert r2.vertices.shape == (0, 2)
210+
assert r2.codes.shape == (0,)
211+
r3 = Path.make_compound_path(Path([(0, 0)]), empty)
212+
assert r3.vertices.shape == (1, 2)
213+
assert r3.codes.shape == (1,)
208214

209215

210216
def test_make_compound_path_stops():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.