10000 Trivial bezier cleanups. by anntzer · Pull Request #13300 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Trivial bezier cleanups. #13300

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
Jan 28, 2019
Merged
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
28 changes: 9 additions & 19 deletions lib/matplotlib/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def find_control_points(c1x, c1y, mmx, mmy, c2x, c2y):

def make_wedged_bezier2(bezier2, width, w1=1., wm=0.5, w2=0.):
"""
Being similar to get_parallels, returns control points of two quadrativ
Being similar to get_parallels, returns control points of two quadratic
bezier lines having a width roughly parallel to given one separated by
*width*.
"""
Expand Down Expand Up @@ -460,31 +460,21 @@ def make_wedged_bezier2(bezier2, width, w1=1., wm=0.5, w2=0.):

def make_path_regular(p):
"""
fill in the codes if None.
If the :attr:`codes` attribute of `Path` *p* is None, return a copy of *p*
with the :attr:`codes` set to (MOVETO, LINETO, LINETO, ..., LINETO);
otherwise return *p* itself.
"""
c = p.codes
if c is None:
c = np.empty(p.vertices.shape[:1], "i")
c.fill(Path.LINETO)
c = np.full(len(p.vertices), Path.LINETO, dtype=Path.code_type)
c[0] = Path.MOVETO

return Path(p.vertices, c)
else:
return p


def concatenate_paths(paths):
"""
concatenate list of paths into a single path.
"""

vertices = []
codes = []
for p in paths:
p = make_path_regular(p)
vertices.append(p.vertices)
codes.append(p.codes)

_path = Path(np.concatenate(vertices),
np.concatenate(codes))
return _path
"""Concatenate a list of paths into a single path."""
vertices = np.concatenate([p.vertices for p in paths])
codes = np.concatenate([make_path_regular(p).codes for p in paths])
return Path(vertices, codes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just out of curiosity, is it really better to do the paths-loop twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't done any timings, but I'd bet that the double loop is compensated by the fact that Python knows this is a list comprehension (and can generate the appropriate bytecode) instead of having to lookup what vertices.append and codes.append do at every iteration.

0