@@ -74,13 +74,15 @@ class Path(object):
74
74
75
75
"""
76
76
77
+ code_type = np .uint8
78
+
77
79
# Path codes
78
- STOP = 0 # 1 vertex
79
- MOVETO = 1 # 1 vertex
80
- LINETO = 2 # 1 vertex
81
- CURVE3 = 3 # 2 vertices
82
- CURVE4 = 4 # 3 vertices
83
- CLOSEPOLY = 79 # 1 vertex
80
+ STOP = code_type ( 0 ) # 1 vertex
81
+ MOVETO = code_type ( 1 ) # 1 vertex
82
+ LINETO = code_type ( 2 ) # 1 vertex
83
+ CURVE3 = code_type ( 3 ) # 2 vertices
84
+ CURVE4 = code_type ( 4 ) # 3 vertices
85
+ CLOSEPOLY = code_type ( 79 ) # 1 vertex
84
86
85
87
#: A dictionary mapping Path codes to the number of vertices that the
86
88
#: code expects.
@@ -91,8 +93,6 @@ class Path(object):
91
93
CURVE4 : 3 ,
92
94
CLOSEPOLY : 1 }
93
95
94
- code_type = np .uint8
95
-
96
96
def __init__ (self , vertices , codes = None , _interpolation_steps = 1 ,
97
97
closed = False , readonly = False ):
98
98
"""
@@ -399,24 +399,22 @@ def iter_segments(self, transform=None, remove_nans=True, clip=None,
399
399
snap = snap , stroke_width = stroke_width ,
400
400
simplify = simplify , curves = curves ,
401
401
sketch = sketch )
402
- vertices = cleaned .vertices
403
- codes = cleaned .codes
404
- len_vertices = vertices .shape [0 ]
405
402
406
403
# Cache these object lookups for performance in the loop.
407
404
NUM_VERTICES_FOR_CODE = self .NUM_VERTICES_FOR_CODE
408
405
STOP = self .STOP
409
406
410
- i = 0
411
- while i < len_vertices :
412
- code = codes [ i ]
407
+ vertices = iter ( cleaned . vertices )
408
+ codes = iter ( cleaned . codes )
409
+ for curr_vertices , code in zip ( vertices , codes ):
413
410
if code == STOP :
414
- return
415
- else :
416
- num_vertices = NUM_VERTICES_FOR_CODE [code ]
417
- curr_vertices = vertices [i :i + num_vertices ].flatten ()
418
- yield curr_vertices , code
419
- i += num_vertices
411
+ break
412
+ extra_vertices = NUM_VERTICES_FOR_CODE [code ] - 1
413
+ if extra_vertices :
414
+ for i in range (extra_vertices ):
415
+ next (codes )
416
+ curr_vertices = np .append (curr_vertices , next (vertices ))
417
+ yield curr_vertices , code
420
418
421
419
def cleaned (self , transform = None , remove_nans = False , clip = None ,
422
420
quantize = False , simplify = False , curves = False ,
0 commit comments