MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / iter_bezier

Method iter_bezier

lib/matplotlib/path.py:432–477  ·  view source on GitHub ↗

Iterate over each Bézier curve (lines included) in a `Path`. Parameters ---------- **kwargs Forwarded to `.iter_segments`. Yields ------ B : `~matplotlib.bezier.BezierSegment` The Bézier curves that make up the curren

(self, **kwargs)

Source from the content-addressed store, hash-verified

430 yield curr_vertices, code
431
432 def iter_bezier(self, **kwargs):
433 """
434 Iterate over each Bézier curve (lines included) in a `Path`.
435
436 Parameters
437 ----------
438 **kwargs
439 Forwarded to `.iter_segments`.
440
441 Yields
442 ------
443 B : `~matplotlib.bezier.BezierSegment`
444 The Bézier curves that make up the current path. Note in particular
445 that freestanding points are Bézier curves of order 0, and lines
446 are Bézier curves of order 1 (with two control points).
447 code : `~matplotlib.path.Path.code_type`
448 The code describing what kind of curve is being returned.
449 `MOVETO`, `LINETO`, `CURVE3`, and `CURVE4` correspond to
450 Bézier curves with 1, 2, 3, and 4 control points (respectively).
451 `CLOSEPOLY` is a `LINETO` with the control points correctly
452 chosen based on the start/end points of the current stroke.
453 """
454 first_vert = None
455 prev_vert = None
456 for verts, code in self.iter_segments(**kwargs):
457 if first_vert is None:
458 if code != Path.MOVETO:
459 raise ValueError("Malformed path, must start with MOVETO.")
460 if code == Path.MOVETO: # a point is like "CURVE1"
461 first_vert = verts
462 yield BezierSegment(np.array([first_vert])), code
463 elif code == Path.LINETO: # "CURVE2"
464 yield BezierSegment(np.array([prev_vert, verts])), code
465 elif code == Path.CURVE3:
466 yield BezierSegment(np.array([prev_vert, verts[:2],
467 verts[2:]])), code
468 elif code == Path.CURVE4:
469 yield BezierSegment(np.array([prev_vert, verts[:2],
470 verts[2:4], verts[4:]])), code
471 elif code == Path.CLOSEPOLY:
472 yield BezierSegment(np.array([prev_vert, first_vert])), code
473 elif code == Path.STOP:
474 return
475 else:
476 raise ValueError(f"Invalid Path.code_type: {code}")
477 prev_vert = verts[-2:]
478
479 def _iter_connected_components(self):
480 """Return subpaths split at MOVETOs."""

Callers 2

get_extentsMethod · 0.95
_update_patch_limitsMethod · 0.80

Calls 2

iter_segmentsMethod · 0.95
BezierSegmentClass · 0.85

Tested by

no test coverage detected