Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Simplify some patches path definitions. #24304

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
Nov 23, 2022
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
74 changes: 29 additions & 45 deletions 74 lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,21 +1209,15 @@ def _recompute_path(self):
# followed by a reversed and scaled inner ring
v1 = arc.vertices
v2 = arc.vertices[::-1] * (self.r - self.width) / self.r
v = np.concatenate([v1, v2, [v1[0, :], (0, 0)]])
c = np.concatenate([
arc.codes, arc.codes, [connector, Path.CLOSEPOLY]])
c[len(arc.codes)] = connector
v = np.concatenate([v1, v2, [(0, 0)]])
c = [*arc.codes, connector, *arc.codes[1:], Path.CLOSEPOLY]
timhoffm marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

In the case of a full anuulus will this result in an extra line connecting the inner and outer rings?

Copy link
Contributor Author

@anntzer anntzer Nov 1, 2022

Choose a reason for hiding this comment

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

No, because for full annuli(?) the connector is MOVETO, which defines a new initial point for a subpath, and CLOSEPOLY closes to that initial point. You can check with e.g.

from pylab import *; w = mpl.patches.Wedge((.5, .5), .3, 0, 360, width=.1, linewidth=5, facecolor="none", edgecolor="k"); figure().add_subplot(aspect=1).add_artist(w)

Copy link
Member

@QuLogic QuLogic Nov 2, 2022

Choose a reason for hiding this comment

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

Shouldn't the outer arc be CLOSEPOLY'd as well, then? I agree the new stuff won't break it, but that seems the semantically correct thing to do (and the existing code didn't do it correctly.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair, but I think that's something that should be fixed at the level of Path.arc(), not here.

else:
# Wedge doesn't need an inner ring
v = np.concatenate([
arc.vertices, [(0, 0), arc.vertices[0, :], (0, 0)]])
c = np.concatenate([
arc.codes, [connector, connector, Path.CLOSEPOLY]])
v = np.concatenate([arc.vertices, [(0, 0), (0, 0)]])
c = [*arc.codes, connector, Path.CLOSEPOLY]

# Shift and scale the wedge to the final location.
v *= self.r
v += np.asarray(self.center)
self._path = Path(v, c)
self._path = Path(v * self.r + self.center, c)

def set_center(self, center):
self._path = None
Expand Down Expand Up @@ -2480,9 +2474,7 @@ def __call__(self, x0, y0, width, height, mutation_size):
Path.CURVE3, Path.CURVE3,
Path.CLOSEPOLY]

path = Path(cp, com)

return path
return Path(cp, com)

@_register_style(_style_list)
class Round4:
Expand Down Expand Up @@ -2531,9 +2523,7 @@ def __call__(self, x0, y0, width, height, mutation_size):
Path.CURVE4, Path.CURVE4, Path.CURVE4,
Path.CLOSEPOLY]

path = Path(cp, com)

return path
return Path(cp, com)

@_register_style(_style_list)
class Sawtooth:
Expand Down Expand Up @@ -2628,8 +2618,7 @@ def _get_sawtooth_vertices(self, x0, y0, width, height, mutation_size):
def __call__(self, x0, y0, width, height, mutation_size):
saw_vertices = self._get_sawtooth_vertices(x0, y0, width,
height, mutation_size)
path = Path(saw_vertices, closed=True)
return path
return Path(saw_vertices, closed=True)

@_register_style(_style_list)
class Roundtooth(Sawtooth):
Expand Down Expand Up @@ -3419,22 +3408,20 @@ def transmute(self, path, mutation_size, linewidth):

# This simple code will not work if ddx, ddy is greater than the
# separation between vertices.
_path = [Path(np.concatenate([[(x0 + ddxA, y0 + ddyA)],
paths = [Path(np.concatenate([[(x0 + ddxA, y0 + ddyA)],
path.vertices[1:-1],
[(x3 + ddxB, y3 + ddyB)]]),
path.codes)]
_fillable = [False]
fills = [False]

if has_begin_arrow:
if self.fillbegin:
p = np.concatenate([verticesA, [verticesA[0],
verticesA[0]], ])
c = np.concatenate([codesA, [Path.LINETO, Path.CLOSEPOLY]])
_path.append(Path(p, c))
_fillable.append(True)
paths.append(
Path([*verticesA, (0, 0)], [*codesA, Path.CLOSEPOLY]))
fills.append(True)
else:
_path.append(Path(verticesA, codesA))
_fillable.append(False)
paths.append(Path(verticesA, codesA))
fills.append(False)
elif self._beginarrow_bracket:
x0, y0 = path.vertices[0]
x1, y1 = path.vertices[1]
Expand All @@ -3443,19 +3430,17 @@ def transmute(self, path, mutation_size, linewidth):
self.lengthA * scaleA,
self.angleA)

_path.append(Path(verticesA, codesA))
_fillable.append(False)
paths.append(Path(verticesA, codesA))
fills.append(False)

if has_end_arrow:
if self.fillend:
_fillable.append(True)
p = np.concatenate([verticesB, [verticesB[0],
verticesB[0]], ])
c = np.concatenate([codesB, [Path.LINETO, Path.CLOSEPOLY]])
_path.append(Path(p, c))
fills.append(True)
paths.append(
Path([*verticesB, (0, 0)], [*codesB, Path.CLOSEPOLY]))
else:
_fillable.append(False)
_path.append(Path(verticesB, codesB))
fills.append(False)
paths.append(Path(verticesB, codesB))
elif self._endarrow_bracket:
x0, y0 = path.vertices[-1]
x1, y1 = path.vertices[-2]
Expand All @@ -3464,10 +3449,10 @@ def transmute(self, path, mutation_size, linewidth):
self.lengthB * scaleB,
self.angleB)

_path.append(Path(verticesB, codesB))
_fillable.append(False)
paths.append(Path(verticesB, codesB))
fills.append(False)

return _path, _fillable
return paths, fills

@_register_style(_style_list, name="-")
class Curve(_Curve):
Expand Down Expand Up @@ -3662,8 +3647,7 @@ def transmute(self, path, mutation_size, linewidth):

try:
arrow_out, arrow_in = \
split_bezier_intersecting_with_closedpath(
arrow_path, in_f, tolerance=0.01)
split_bezier_intersecting_with_closedpath(arrow_path, in_f)
except NonIntersectingPathException:
# if this happens, make a straight line of the head_length
# long.
Expand Down Expand Up @@ -3743,7 +3727,7 @@ def transmute(self, path, mutation_size, linewidth):
in_f = inside_circle(x2, y2, head_length)
try:
path_out, path_in = split_bezier_intersecting_with_closedpath(
arrow_path, in_f, tolerance=0.01)
arrow_path, in_f)
except NonIntersectingPathException:
# if this happens, make a straight line of the head_length
# long.
Expand All @@ -3757,7 +3741,7 @@ def transmute(self, path, mutation_size, linewidth):
# path for head
in_f = inside_circle(x2, y2, head_length * .8)
path_out, path_in = split_bezier_intersecting_with_closedpath(
arrow_path, in_f, tolerance=0.01)
arrow_path, in_f)
path_tail = path_out

# head
Expand All @@ -3775,7 +3759,7 @@ def transmute(self, path, mutation_size, linewidth):
# path for head
in_f = inside_circle(x0, y0, tail_width * .3)
path_in, path_out = split_bezier_intersecting_with_closedpath(
arrow_path, in_f, tolerance=0.01)
arrow_path, in_f)
tail_start = path_in[-1]

head_right, head_left = head_r, head_l
Expand Down
1 change: 0 additions & 1 deletion 1 lib/matplotlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,6 @@ def clip_to_bbox(self, bbox, inside=True):
If *inside* is `True`, clip to the inside of the box, otherwise
to the outside of the box.
"""
# Use make_compound_path_from_polys
verts = _path.clip_path_to_rect(self, bbox, inside)
paths = [Path(poly) for poly in verts]
return self.make_compound_path(*paths)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.