8000 fix bug where make_compound_path kept all STOPs · matplotlib/matplotlib@eb4b15b · GitHub
[go: up one dir, main page]

Skip to content

Commit eb4b15b

Browse files
committed
fix bug where make_compound_path kept all STOPs
1 parent 2c845db commit eb4b15b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/matplotlib/path.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ def make_compound_path(cls, *args):
330330
if not args:
331331
return Path(np.empty([0, 2], dtype=np.float32))
332332

333+
# concatenate paths
333334
vertices = np.concatenate([x.vertices for x in args])
334335
codes = np.empty(len(vertices), dtype=cls.code_type)
335336
i = 0
@@ -341,6 +342,16 @@ def make_compound_path(cls, *args):
341342
codes[i:i + len(path.codes)] = path.codes
342343
i += len(path.vertices)
343344

345+
# remove internal STOP's, replace kinal stop if present
346+
last_vert = None
347+
if codes.size > 0 and codes[-1] == cls.STOP:
348+
last_vert = vertices[-1]
349+
vertices = vertices[codes != cls.STOP, :]
350+
codes = codes[codes != cls.STOP]
351+
if last_vert is not None:
352+
vertices = np.append(vertices, [last_vert], axis=0)
353+
codes = np.append(codes, cls.STOP)
354+
344355
return cls(vertices, codes)
345356

346357
def __repr__(self):

lib/matplotlib/tests/test_path.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ 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+
assert np.sum(compound_path.codes == Path.STOP) == 1
155+
156+
150157
@image_comparison(['xkcd.png'], remove_text=True)
151158
def test_xkcd():
152159
np.random.seed(0)

0 commit comments

Comments
 (0)
0