Skip to content

Commit d40feb0

Browse files
authored
Merge pull request matplotlib#24304 from anntzer/cp
MNT: Simplify some patches path definitions.
2 parents 92b643f + 73622a0 commit d40feb0

File tree

2 files changed

+28
-43
lines changed

2 files changed

+28
-43
lines changed

lib/matplotlib/patches.py

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,16 +1210,12 @@ def _recompute_path(self):
12101210
# followed by a reversed and scaled inner ring
12111211
v1 = arc.vertices
12121212
v2 = arc.vertices[::-1] * (self.r - self.width) / self.r
1213-
v = np.concatenate([v1, v2, [v1[0, :], (0, 0)]])
1214-
c = np.concatenate([
1215-
arc.codes, arc.codes, [connector, Path.CLOSEPOLY]])
1216-
c[len(arc.codes)] = connector
1213+
v = np.concatenate([v1, v2, [(0, 0)]])
1214+
c = [*arc.codes, connector, *arc.codes[1:], Path.CLOSEPOLY]
12171215
else:
12181216
# Wedge doesn't need an inner ring
1219-
v = np.concatenate([
1220-
arc.vertices, [(0, 0), arc.vertices[0, :], (0, 0)]])
1221-
c = np.concatenate([
1222-
arc.codes, [connector, connector, Path.CLOSEPOLY]])
1217+
v = np.concatenate([arc.vertices, [(0, 0), (0, 0)]])
1218+
c = [*arc.codes, connector, Path.CLOSEPOLY]
12231219

12241220
# Shift and scale the wedge to the final location.
12251221
self._path = Path(v * self.r + self.center, c)
@@ -2478,9 +2474,7 @@ def __call__(self, x0, y0, width, height, mutation_size):
24782474
Path.CURVE3, Path.CURVE3,
24792475
Path.CLOSEPOLY]
24802476

2481-
path = Path(cp, com)
2482-
2483-
return path
2477+
return Path(cp, com)
24842478

24852479
@_register_style(_style_list)
24862480
class Round4:
@@ -2529,9 +2523,7 @@ def __call__(self, x0, y0, width, height, mutation_size):
25292523
Path.CURVE4, Path.CURVE4, Path.CURVE4,
25302524
Path.CLOSEPOLY]
25312525

2532-
path = Path(cp, com)
2533-
2534-
return path
2526+
return Path(cp, com)
25352527

25362528
@_register_style(_style_list)
25372529
class Sawtooth:
@@ -2626,8 +2618,7 @@ def _get_sawtooth_vertices(self, x0, y0, width, height, mutation_size):
26262618
def __call__(self, x0, y0, width, height, mutation_size):
26272619
saw_vertices = self._get_sawtooth_vertices(x0, y0, width,
26282620
height, mutation_size)
2629-
path = Path(saw_vertices, closed=True)
2630-
return path
2621+
return Path(saw_vertices, closed=True)
26312622

26322623
@_register_style(_style_list)
26332624
class Roundtooth(Sawtooth):
@@ -3383,22 +3374,20 @@ def transmute(self, path, mutation_size, linewidth):
33833374

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

33923383
if has_begin_arrow:
33933384
if self.fillbegin:
3394-
p = np.concatenate([verticesA, [verticesA[0],
3395-
verticesA[0]], ])
3396-
c = np.concatenate([codesA, [Path.LINETO, Path.CLOSEPOLY]])
3397-
_path.append(Path(p, c))
3398-
_fillable.append(True)
3385+
paths.append(
3386+
Path([*verticesA, (0, 0)], [*codesA, Path.CLOSEPOLY]))
3387+
fills.append(True)
33993388
else:
3400-
_path.append(Path(verticesA, codesA))
3401-
_fillable.append(False)
3389+
paths.append(Path(verticesA, codesA))
3390+
fills.append(False)
34023391
elif self._beginarrow_bracket:
34033392
x0, y0 = path.vertices[0]
34043393
x1, y1 = path.vertices[1]
@@ -3407,19 +3396,17 @@ def transmute(self, path, mutation_size, linewidth):
34073396
self.lengthA * scaleA,
34083397
self.angleA)
34093398

3410-
_path.append(Path(verticesA, codesA))
3411-
_fillable.append(False)
3399+
paths.append(Path(verticesA, codesA))
3400+
fills.append(False)
34123401

34133402
if has_end_arrow:
34143403
if self.fillend:
3415-
_fillable.append(True)
3416-
p = np.concatenate([verticesB, [verticesB[0],
3417-
verticesB[0]], ])
3418-
c = np.concatenate([codesB, [Path.LINETO, Path.CLOSEPOLY]])
3419-
_path.append(Path(p, c))
3404+
fills.append(True)
3405+
paths.append(
3406+
Path([*verticesB, (0, 0)], [*codesB, Path.CLOSEPOLY]))
34203407
else:
3421-
_fillable.append(False)
3422-
_path.append(Path(verticesB, codesB))
3408+
fills.append(False)
3409+
paths.append(Path(verticesB, codesB))
34233410
elif self._endarrow_bracket:
34243411
x0, y0 = path.vertices[-1]
34253412
x1, y1 = path.vertices[-2]
@@ -3428,10 +3415,10 @@ def transmute(self, path, mutation_size, linewidth):
34283415
self.lengthB * scaleB,
34293416
self.angleB)
34303417

3431-
_path.append(Path(verticesB, codesB))
3432-
_fillable.append(False)
3418+
paths.append(Path(verticesB, codesB))
3419+
fills.append(False)
34333420

3434-
return _path, _fillable
3421+
return paths, fills
34353422

34363423
@_register_style(_style_list, name="-")
34373424
class Curve(_Curve):
@@ -3626,8 +3613,7 @@ def transmute(self, path, mutation_size, linewidth):
36263613

36273614
try:
36283615
arrow_out, arrow_in = \
3629-
split_bezier_intersecting_with_closedpath(
3630-
arrow_path, in_f, tolerance=0.01)
3616+
split_bezier_intersecting_with_closedpath(arrow_path, in_f)
36313617
except NonIntersectingPathException:
36323618
# if this happens, make a straight line of the head_length
36333619
# long.
@@ -3707,7 +3693,7 @@ def transmute(self, path, mutation_size, linewidth):
37073693
in_f = inside_circle(x2, y2, head_length)
37083694
try:
37093695
path_out, path_in = split_bezier_intersecting_with_closedpath(
3710-
arrow_path, in_f, tolerance=0.01)
3696+
arrow_path, in_f)
37113697
except NonIntersectingPathException:
37123698
# if this happens, make a straight line of the head_length
37133699
# long.
@@ -3721,7 +3707,7 @@ def transmute(self, path, mutation_size, linewidth):
37213707
# path for head
37223708
in_f = inside_circle(x2, y2, head_length * .8)
37233709
path_out, path_in = split_bezier_intersecting_with_closedpath(
3724-
arrow_path, in_f, tolerance=0.01)
3710+
arrow_path, in_f)
37253711
path_tail = path_out
37263712

37273713
# head
@@ -3739,7 +3725,7 @@ def transmute(self, path, mutation_size, linewidth):
37393725
# path for head
37403726
in_f = inside_circle(x0, y0, tail_width * .3)
37413727
path_in, path_out = split_bezier_intersecting_with_closedpath(
3742-
arrow_path, in_f, tolerance=0.01)
3728+
arrow_path, in_f)
37433729
tail_start = path_in[-1]
37443730

37453731
head_right, head_left = head_r, head_l

lib/matplotlib/path.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,6 @@ def clip_to_bbox(self, bbox, inside=True):
10401040
If *inside* is `True`, clip to the inside of the box, otherwise
10411041
to the outside of the box.
10421042
"""
1043-
# Use make_compound_path_from_polys
10441043
verts = _path.clip_path_to_rect(self, bbox, inside)
10451044
paths = [Path(poly) for poly in verts]
10461045
return self.make_compound_path(*paths)

0 commit comments

Comments
 (0)