-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the outer arc be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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: | ||
|
@@ -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: | ||
|
@@ -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): | ||
|
@@ -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] | ||
|
@@ -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] | ||
|
@@ -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): | ||
|
@@ -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. | ||
|
@@ -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. | ||
|
@@ -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 | ||
|
@@ -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 | ||
|
Uh oh!
There was an error while loading. Please reload this page.