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

Skip to content

Support make_compound_path concatenating only empty paths. #25252

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 1 commit into from
Feb 20, 2023
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
26 changes: 11 additions & 15 deletions lib/matplotlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,29 +318,25 @@ def make_compound_path_from_polys(cls, XY):

@classmethod
def make_compound_path(cls, *args):
r"""
Concatenate a list of `Path`\s into a single `.Path`, removing all `.STOP`\s.
"""
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])
vertices = np.concatenate([path.vertices for path in args])
codes = np.empty(len(vertices), dtype=cls.code_type)
i = 0
for path in args:
size = len(path.vertices)
if path.codes is None:
codes[i] = cls.MOVETO
codes[i + 1:i + len(path.vertices)] = cls.LINETO
if size:
codes[i] = cls.MOVETO
codes[i+1:i+size] = cls.LINETO
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)
codes[i:i+size] = path.codes
i += size
not_stop_mask = codes != cls.STOP # Remove STOPs, as internal STOPs are a bug.
return cls(vertices[not_stop_mask], codes[not_stop_mask])

def __repr__(self):
return f"Path({self.vertices!r}, {self.codes!r})"
Expand Down
10 changes: 8 additions & 2 deletions lib/matplotlib/tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,14 @@ def test_log_transform_with_zero():
def test_make_compound_path_empty():
# We should be able to make a compound path with no arguments.
# This makes it easier to write generic path based code.
r = Path.make_compound_path()
assert r.vertices.shape == (0, 2)
empty = Path.make_compound_path()
assert empty.vertices.shape == (0, 2)
r2 = Path.make_compound_path(empty, empty)
assert r2.vertices.shape == (0, 2)
assert r2.codes.shape == (0,)
r3 = Path.make_compound_path(Path([(0, 0)]), empty)
assert r3.vertices.shape == (1, 2)
assert r3.codes.shape == (1,)


def test_make_compound_path_stops():
Expand Down