Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix bug where make_compound_path kept all STOPs #16822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions lib/matplotlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,13 @@ def make_compound_path_from_polys(cls, XY):

@classmethod
def make_compound_path(cls, *args):
"""Make a compound path from a list of Path objects."""
"""
Make a compound path from a list of Path objects. Blindly removes all
Path.STOP control points.
"""
# Handle an empty list in args (i.e. no args).
if not args:
return Path(np.empty([0, 2], dtype=np.float32))

vertices = np.concatenate([x.vertices for x in args])
codes = np.empty(len(vertices), dtype=cls.code_type)
i = 0
Expand All @@ -340,6 +342,10 @@ def make_compound_path(cls, *args):
else:
codes[i:i + len(path.codes)] = path.codes
i += len(path.vertices)
# remove STOP's, since internal STOPs are a bug
not_stop_mask = codes != cls.STOP
vertices = vertices[not_stop_mask, :]
codes = codes[not_stop_mask]

return cls(vertices, codes)

Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ 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)
# the choice to not preserve the terminal STOP is arbitrary, but
# documented, so we test that it is in fact respected here
assert np.sum(compound_path.codes == Path.STOP) == 0


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