@@ -95,6 +95,9 @@ class Path:
95
95
CURVE4 : 3 ,
96
96
CLOSEPOLY : 1 }
97
97
98
+ # A list of path codes for which the vertices are ignored
99
+ IGNORED_CODES = [STOP , CLOSEPOLY ]
100
+
98
101
def __init__ (self , vertices , codes = None , _interpolation_steps = 1 ,
99
102
closed = False , readonly = False ):
100
103
"""
@@ -620,11 +623,20 @@ def get_extents(self, transform=None, **kwargs):
620
623
self = transform .transform_path (self )
621
624
if self .codes is None :
622
625
xys = self .vertices
626
+ # Short cut the case with only straight lines
623
627
elif len (np .intersect1d (self .codes , [Path .CURVE3 , Path .CURVE4 ])) == 0 :
624
- xys = self .vertices [self .codes != Path .CLOSEPOLY ]
628
+ draw_idxs = np .in1d (self .codes , Path .LINETO )
629
+ # Include the start and end point of each line
630
+ draw_idxs = draw_idxs | np .roll (draw_idxs , - 1 )
631
+ # Add in commands that aren't ignored
632
+ # (in the straight line case here this is only MOVETO)
633
+ draw_idxs = draw_idxs | ~ np .in1d (self .codes , Path .IGNORED_CODES )
634
+ xys = self .vertices [draw_idxs ]
625
635
else :
626
636
xys = []
627
637
for curve , code in self .iter_bezier (** kwargs ):
638
+ if code in Path .IGNORED_CODES :
639
+ continue
628
640
# places where the derivative is zero can be extrema
629
641
_ , dzeros = curve .axis_aligned_extrema ()
630
642
# as can the ends of the curve
0 commit comments