@@ -432,13 +432,10 @@ def iter_segments(self, transform=None, remove_nans=True, clip=None,
432
432
curr_vertices = np .append (curr_vertices , next (vertices ))
433
433
yield curr_vertices , code
434
434
435
- def iter_curves (self , ** kwargs ):
435
+ def iter_bezier (self , ** kwargs ):
436
436
"""
437
437
Iterate over each bezier curve (lines included) in a Path.
438
438
439
- This is in contrast to iter_segments, which omits the first control
440
- point of each curve.
441
-
442
439
Parameters
443
440
----------
444
441
kwargs : Dict[str, object]
@@ -455,30 +452,33 @@ def iter_curves(self, **kwargs):
455
452
The code describing what kind of curve is being returned.
456
453
Path.MOVETO, Path.LINETO, Path.CURVE3, Path.CURVE4 correspond to
457
454
bezier curves with 1, 2, 3, and 4 control points (respectively).
455
+ Path.CLOSEPOLY is a Path.LINETO with the control points correctly
456
+ chosen based on the start/end points of the current stroke.
458
457
"""
459
- first_vertex = None
460
- prev_vertex = None
458
+ first_vert = None
459
+ prev_vert = None
461
460
for vertices , code in self .iter_segments (** kwargs ):
462
- if first_vertex is None :
461
+ if first_vert is None :
463
462
if code != Path .MOVETO :
464
463
raise ValueError ("Malformed path, must start with MOVETO." )
465
464
if code == Path .MOVETO : # a point is like "CURVE1"
466
- first_vertex = vertices
467
- yield np .array ([first_vertex ] ), code
465
+ first_vert = vertices
466
+ yield BezierSegment ( np .array ([first_vert ]) ), code
468
467
elif code == Path .LINETO : # "CURVE2"
469
- yield np .array ([prev_vertex , vertices ]), code
468
+ yield BezierSegment ( np .array ([prev_vert , vertices ]) ), code
470
469
elif code == Path .CURVE3 :
471
- yield np .array ([prev_vertex , vertices [:2 ], vertices [2 :]]), code
470
+ yield BezierSegment (np .array ([prev_vert , vertices [:2 ],
471
+ vertices [2 :]])), code
472
472
elif code == Path .CURVE4 :
473
- yield np .array ([prev_vertex , vertices [:2 ], vertices [ 2 : 4 ],
474
- vertices [4 :]]), code
473
+ yield BezierSegment ( np .array ([prev_vert , vertices [:2 ],
474
+ vertices [ 2 : 4 ], vertices [4 :]]) ), code
475
475
elif code == Path .CLOSEPOLY :
476
- yield np .array ([prev_vertex , first_vertex ] ), code
476
+ yield BezierSegment ( np .array ([prev_vert , first_vert ]) ), code
477
477
elif code == Path .STOP :
478
478
return
479
479
else :
480
480
raise ValueError ("Invalid Path.code_type: " + str (code ))
481
- prev_vertex = vertices [- 2 :]
481
+ prev_vert = vertices [- 2 :]
482
482
483
483
@cbook ._delete_parameter ("3.3" , "quantize" )
484
484
def cleaned (self , transform = None , remove_nans = False , clip = None ,
@@ -611,7 +611,7 @@ def get_exact_extents(self, **kwargs):
611
611
Parameters
612
612
----------
613
613
kwargs : Dict[str, object]
614
- Forwarded to self.iter_curves .
614
+ Forwarded to self.iter_bezier .
615
615
616
616
Returns
617
617
-------
@@ -621,8 +621,7 @@ def get_exact_extents(self, **kwargs):
621
621
maxi = 2 # [xmin, ymin, *xmax, ymax]
622
622
# return value for empty paths to match _path.h
623
623
extents = np .array ([np .inf , np .inf , - np .inf , - np .inf ])
624
- for curve , code in self .iter_curves (** kwargs ):
625
- curve = BezierSegment (curve )
624
+ for curve , code in self .iter_bezier (** kwargs ):
626
625
# start and endpoints can be extrema of the curve
627
626
_update_extents (extents , curve (0 )) # start point
628
627
_update_extents (extents , curve (1 )) # end point
0 commit comments