8000 do not retain any STOPs in make_compound_path · matplotlib/matplotlib@95b33b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95b33b1

Browse files
committed
do not retain any STOPs in make_compound_path
1 parent eb4b15b commit 95b33b1

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

lib/matplotlib/path.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +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-
333-
# concatenate paths
334335
vertices = np.concatenate([x.vertices for x in args])
335336
codes = np.empty(len(vertices), dtype=cls.code_type)
336337
i = 0
@@ -341,16 +342,10 @@ def make_compound_path(cls, *args):
341342
else:
342343
codes[i:i + len(path.codes)] = path.codes
343344
i += len(path.vertices)
344-
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)
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]
354349

355350
return cls(vertices, codes)
356351

lib/matplotlib/tests/test_path.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ def test_make_compound_path_stops():
151151
zero = [0, 0]
152152
paths = 3*[Path([zero, zero], [Path.MOVETO, Path.STOP])]
153153
compound_path = Path.make_compound_path(*paths)
154-
assert np.sum(compound_path.codes == Path.STOP) == 1
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
155157

156158

157159
@image_comparison(['xkcd.png'], remove_text=True)

0 commit comments

Comments
 (0)
0