def iter_segments(self, simplify=None):
vertices = self.vertices<EOL>if not len(vertices):<EOL><INDENT>return<EOL><DEDENT>codes        = self.codes<EOL>len_vertices = len(vertices)<EOL>isfinite     = np.isfinite<EOL>NUM_VERTICES = self.NUM_VERTICES<EOL>MOVETO       = self.MOVETO<EOL>LINETO       = self.LINETO<EOL>CLOSEPOLY    = self.CLOSEPOLY<EOL>STOP         = self.STOP<EOL>if simplify is not None and self.should_simplify:<EOL><INDENT>polygons = self.to_polygons(None, *simplify)<EOL>for vertices in polygons:<EOL><INDENT>yield vertices[<NUM_LIT:0>], MOVETO<EOL>for v in vertices[<NUM_LIT:1>:]:<EOL><INDENT>yield v, LINETO<EOL><DEDENT><DEDENT><DEDENT>elif codes is None:<EOL><INDENT>if self.has_nonfinite:<EOL><INDENT>next_code = MOVETO<EOL>for v in vertices:<EOL><INDENT>if np.isfinite(v).all():<EOL><INDENT>yield v, next_code<EOL>next_code = LINETO<EOL><DEDENT>else:<EOL><INDENT>next_code = MOVETO<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>yield vertices[<NUM_LIT:0>], MOVETO<EOL>for v in vertices[<NUM_LIT:1>:]:<EOL><INDENT>yield v, LINETO<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>i = <NUM_LIT:0><EOL>was_nan = False<EOL>while i < len_vertices:<EOL><INDENT>code = codes[i]<EOL>if code == CLOSEPOLY:<EOL><INDENT>yield [], code<EOL>i += <NUM_LIT:1><EOL><DEDENT>elif code == STOP:<EOL><INDENT>return<EOL><DEDENT>else:<EOL><INDENT>num_vertices = NUM_VERTICES[int(code)]<EOL>curr_vertices = vertices[i:i+num_vertices].flatten()<EOL>if not isfinite(curr_vertices).all():<EOL><INDENT>was_nan = True<EOL><DEDENT>elif was_nan:<EOL><INDENT>yield curr_vertices[-<NUM_LIT:2>:], MOVETO<EOL>was_nan = False<EOL><DEDENT>else:<EOL><INDENT>yield curr_vertices, code<EOL><DEDENT>i += num_vertices<EOL><DEDENT><DEDENT><DEDENT>
Iterates over all of the curve segments in the path.  Each
iteration returns a 2-tuple (*vertices*, *code*), where
*vertices* is a sequence of 1 - 3 coordinate pairs, and *code* is
one of the :class:`Path` codes.

If *simplify* is provided, it must be a tuple (*width*,
*height*) defining the size of the figure, in native units
(e.g. pixels or points).  Simplification implies both removing
adjacent line segments that are very close to parallel, and
removing line segments outside of the figure.  The path will
be simplified *only* if :attr:`should_simplify` is True, which
is determined in the constructor by this criteria:

   - No curves
   - More than 128 vertices