Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/matplotlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ def make_compound_path(cls, *args):
if not args:
return Path(np.empty([0, 2], dtype=np.float32))

# concatenate paths
Comment thread
brunobeltran marked this conversation as resolved.
Resolved
vertices = np.concatenate([x.vertices for x in args])
codes = np.empty(len(vertices), dtype=cls.code_type)
i = 0
Expand All @@ -341,6 +342,16 @@ def make_compound_path(cls, *args):
codes[i:i + len(path.codes)] = path.codes
i += len(path.vertices)

# remove internal STOP's, replace kinal stop if present

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: final

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also not bother with restoring the final STOP given that it doesn't matter and we may deprecate STOPs.
And even though this is clearly a bugfix, it also changes the behavior of the function wrt STOP codes, so it may change it a tiny bit more (in a less observable fashion! the final STOP doesn't matter, unlike the middle ones) to keep the implementation simpler.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that is acceptable, then I will document it and go with ignoring all STOPs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at least for me, it seems ok.

last_vert = None
if codes.size > 0 and codes[-1] == cls.STOP:
last_vert = vertices[-1]
vertices = vertices[codes != cls.STOP, :]
codes = codes[codes != cls.STOP]
Comment thread
brunobeltran marked this conversation as resolved.
Resolved
if last_vert is not None:
vertices = np.append(vertices, [last_vert], axis=0)
codes = np.append(codes, cls.STOP)

return cls(vertices, codes)

def __repr__(self):
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ def test_make_compound_path_empty():
assert r.vertices.shape == (0, 2)


def test_make_compound_path_stops():
zero = [0, 0]
paths = 3*[Path([zero, zero], [Path.MOVETO, Path.STOP])]
compound_path = Path.make_compound_path(*paths)
assert np.sum(compound_path.codes == Path.STOP) == 1


@image_comparison(['xkcd.png'], remove_text=True)
def test_xkcd():
np.random.seed(0)
Expand Down