8000 more clear name: `iter_bezier` · matplotlib/matplotlib@f0571f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f0571f0

Browse files
committed
more clear name: iter_bezier
1 parent d7084de commit f0571f0

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

lib/matplotlib/path.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -432,53 +432,52 @@ def iter_segments(self, transform=None, remove_nans=True, clip=None,
432432
curr_vertices = np.append(curr_vertices, next(vertices))
433433
yield curr_vertices, code
434434

435-
def iter_curves(self, **kwargs):
435+
def iter_bezier(self, **kwargs):
436436
"""
437437
Iterate over each bezier curve (lines included) in a Path.
438438
439-
This is in contrast to iter_segments, which omits the first control
440-
point of each curve.
441-
442439
Parameters
443440
----------
444441
kwargs : Dict[str, object]
445442
Forwareded to iter_segments.
446443
447444
Yields
448445
------
449-
vertices : float, (N, 2) array_like
450-
The N control points of the next 2-dimensional bezier curve making
451-
up self. Note in particular that freestanding points are bezier
452-
curves of order 0, and lines are bezier curves of order 1 (with two
453-
control points).
446+
B : matplotlib.bezier.BezierSegment
447+
The bezier curves that make up the current path. Note in particular
448+
that freestanding points are bezier curves of order 0, and lines
449+
are bezier curves of order 1 (with two control points).
454450
code : Path.code_type
455451
The code describing what kind of curve is being returned.
456452
Path.MOVETO, Path.LINETO, Path.CURVE3, Path.CURVE4 correspond to
457453
bezier curves with 1, 2, 3, and 4 control points (respectively).
454+
Path.CLOSEPOLY is a Path.LINETO with the control points correctly
455+
chosen based on the start/end points of the current stroke.
458456
"""
459-
first_vertex = None
460-
prev_vertex = None
457+
first_vert = None
458+
prev_vert = None
461459
for vertices, code in self.iter_segments(**kwargs):
462-
if first_vertex is None:
460+
if first_vert is None:
463461
if code != Path.MOVETO:
464462
raise ValueError("Malformed path, must start with MOVETO.")
465463
if code == Path.MOVETO: # a point is like "CURVE1"
466-
first_vertex = vertices
467-
yield np.array([first_vertex]), code
464+
first_vert = vertices
465+
yield BezierSegment(np.array([first_vert])), code
468466
elif code == Path.LINETO: # "CURVE2"
469-
yield np.array([prev_vertex, vertices]), code
467+
yield BezierSegment(np.array([prev_vert, vertices])), code
470468
elif code == Path.CURVE3:
471-
yield np.array([prev_vertex, vertices[:2], vertices[2:]]), code
469+
yield BezierSegment(np.array([prev_vert, vertices[:2],
470+
vertices[2:]])), code
472471
elif code == Path.CURVE4:
473-
yield np.array([prev_vertex, vertices[:2], vertices[2:4],
474-
vertices[4:]]), code
472+
yield BezierSegment(np.array([prev_vert, vertices[:2],
473+
vertices[2:4], vertices[4:]])), code
475474
elif code == Path.CLOSEPOLY:
476-
yield np.array([prev_vertex, first_vertex]), code
475+
yield BezierSegment(np.array([prev_vert, first_vert])), code
477476
elif code == Path.STOP:
478477
return
479478
else:
480479
raise ValueError("Invalid Path.code_type: " + str(code))
481-
prev_vertex = vertices[-2:]
480+
prev_vert = vertices[-2:]
482481

483482
@cbook._delete_parameter("3.3", "quantize")
484483
def cleaned(self, transform=None, remove_nans=False, clip=None,
@@ -611,7 +610,7 @@ def get_exact_extents(self, **kwargs):
611610
Parameters
612611
----------
613612
kwargs : Dict[str, object]
614-
Forwarded to self.iter_curves.
613+
Forwarded to self.iter_bezier.
615614
616615
Returns
617616
-------
@@ -621,8 +620,7 @@ def get_exact_extents(self, **kwargs):
621620
maxi = 2 # [xmin, ymin, *xmax, ymax]
622621
# return value for empty paths to match _path.h
623622
extents = np.array([np.inf, np.inf, -np.inf, -np.inf])
624-
for curve, code in self.iter_curves(**kwargs):
625-
curve = BezierSegment(curve)
623+
for curve, code in self.iter_bezier(**kwargs):
626624
# start and endpoints can be extrema of the curve
627625
_update_extents(extents, curve(0)) # start point
628626
_update_extents(extents, curve(1)) # end point

0 commit comments

Comments
 (0)
0