Skip to content

Commit 1632a53

Browse files
authored
Merge pull request #16822 from brunobeltran/compound_path_bug
fix bug where make_compound_path kept all STOPs
2 parents 66c3d4a + 95b33b1 commit 1632a53

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/matplotlib/path.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,13 @@ def make_compound_path_from_polys(cls, XY):
325325

326326
@classmethod
327327
def make_compound_path(cls, *args):
328-
"""Make a compound path from a list of Path objects."""
328+
"""
329+
Make a compound path from a list of Path objects. Blindly removes all
330+
Path.STOP control points.
331+
"""
329332
# Handle an empty list in args (i.e. no args).
330333
if not args:
331334
return Path(np.empty([0, 2], dtype=np.float32))
332-
333335
vertices = np.concatenate([x.vertices for x in args])
334336
codes = np.empty(len(vertices), dtype=cls.code_type)
335337
i = 0
@@ -340,6 +342,10 @@ def make_compound_path(cls, *args):
340342
else:
341343
codes[i:i + len(path.codes)] = path.codes
342344
i += len(path.vertices)
345+
# remove STOP's, since internal STOPs are a bug
346+
not_stop_mask = codes != cls.STOP
347+
vertices = vertices[not_stop_mask, :]
348+
codes = codes[not_stop_mask]
343349

344350
return cls(vertices, codes)
345351

lib/matplotlib/tests/test_path.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ def test_make_compound_path_empty():
147147
assert r.vertices.shape == (0, 2)
148148

149149

150+
def test_make_compound_path_stops():
151+
zero = [0, 0]
152+
paths = 3*[Path([zero, zero], [Path.MOVETO, Path.STOP])]
153+
compound_path = Path.make_compound_path(*paths)
154+
# the choice to not preserve the terminal STOP is arbitrary, but
155+
# documented, so we test that it is in fact respected here
156+
assert np.sum(compound_path.codes == Path.STOP) == 0
157+
158+
150159
@image_comparison(['xkcd.png'], remove_text=True)
151160
def test_xkcd():
152161
np.random.seed(0)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy