@@ -95,6 +95,9 @@ class Path:
95
95
CURVE4 : 3 ,
96
96
CLOSEPOLY : 1 }
97
97
98
+ #: A list of the codes that do not draw anything
99
+ NON_DRAW_CODES = [MOVETO , CLOSEPOLY , STOP ]
100
+
98
101
def __init__ (self , vertices , codes = None , _interpolation_steps = 1 ,
99
102
closed = False , readonly = False ):
100
103
"""
@@ -620,11 +623,17 @@ 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 .nonzero (self .codes == Path .LINETO )[0 ]
629
+ # Include the start and end point of each line
630
+ draw_idxs = np .union1d (draw_idxs , draw_idxs - 1 )
631
+ xys = self .vertices [draw_idxs ]
625
632
else :
626
633
xys = []
627
634
for curve , code in self .iter_bezier (** kwargs ):
635
+ if code in Path .NON_DRAW_CODES :
636
+ continue
628
637
# places where the derivative is zero can be extrema
629
638
_ , dzeros = curve .axis_aligned_extrema ()
630
639
# as can the ends of the curve
0 commit comments