Exemplo n.º 1
0
    def cleaned(self,
                transform=None,
                remove_nans=False,
                clip=None,
                quantize=False,
                simplify=False,
                curves=False,
                stroke_width=1.0,
                snap=False,
                sketch=None):
        """
        Cleans up the path according to the parameters returning a new
        Path instance.

        .. seealso::

            See :meth:`iter_segments` for details of the keyword arguments.

        Returns
        -------
        Path instance with cleaned up vertices and codes.

        """
        vertices, codes = _path.cleanup_path(self, transform, remove_nans,
                                             clip, snap, stroke_width,
                                             simplify, curves, sketch)
        internals = {
            'should_simplify': self.should_simplify and not simplify,
            'has_nonfinite': self.has_nonfinite and not remove_nans,
            'simplify_threshold': self.simplify_threshold,
            'interpolation_steps': self._interpolation_steps
        }
        return Path._fast_from_codes_and_verts(vertices, codes, internals)
Exemplo n.º 2
0
    def cleaned(self, transform=None, remove_nans=False, clip=None,
                  quantize=False, simplify=False, curves=False,
                  stroke_width=1.0, snap=False, sketch=None):
        """
        Cleans up the path according to the parameters returning a new
        Path instance.

        .. seealso::

            See :meth:`iter_segments` for details of the keyword arguments.

        Returns
        -------
        Path instance with cleaned up vertices and codes.

        """
        vertices, codes = _path.cleanup_path(self, transform,
                                             remove_nans, clip,
                                             snap, stroke_width,
                                             simplify, curves, sketch)
        internals = {'should_simplify': self.should_simplify and not simplify,
                     'has_nonfinite': self.has_nonfinite and not remove_nans,
                     'simplify_threshold': self.simplify_threshold,
                     'interpolation_steps': self._interpolation_steps}
        return Path._fast_from_codes_and_verts(vertices, codes, internals)
Exemplo n.º 3
0
    def iter_segments(self, transform=None, remove_nans=True, clip=None,
                      quantize=False, simplify=None, curves=True):
        """
        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.

        Additionally, this method can provide a number of standard
        cleanups and conversions to the path.

        *transform*: if not None, the given affine transformation will
         be applied to the path.

        *remove_nans*: if True, will remove all NaNs from the path and
         insert MOVETO commands to skip over them.

        *clip*: if not None, must be a four-tuple (x1, y1, x2, y2)
         defining a rectangle in which to clip the path.

        *quantize*: if None, auto-quantize.  If True, force quantize,
         and if False, don't quantize.

        *simplify*: if True, perform simplification, to remove
         vertices that do not affect the appearance of the path.  If
         False, perform no simplification.  If None, use the
         should_simplify member variable.

        *curves*: If True, curve segments will be returned as curve
         segments.  If False, all curves will be converted to line
         segments.
        """
        vertices = self.vertices
        if not len(vertices):
            return

        codes        = self.codes

        NUM_VERTICES = self.NUM_VERTICES
        MOVETO       = self.MOVETO
        LINETO       = self.LINETO
        CLOSEPOLY    = self.CLOSEPOLY
        STOP         = self.STOP

        vertices, codes = cleanup_path(self, transform, remove_nans, clip,
                                       quantize, simplify, curves)
        len_vertices = len(vertices)

        i = 0
        while i < len_vertices:
            code = codes[i]
            if code == STOP:
                return
            else:
                num_vertices = NUM_VERTICES[int(code) & 0xf]
                curr_vertices = vertices[i:i+num_vertices].flatten()
                yield curr_vertices, code
                i += num_vertices
Exemplo n.º 4
0
    def iter_segments(self, transform=None, remove_nans=True, clip=None,
                      quantize=False, simplify=None, curves=True):
        """
        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.

        Additionally, this method can provide a number of standard
        cleanups and conversions to the path.

        *transform*: if not None, the given affine transformation will
         be applied to the path.

        *remove_nans*: if True, will remove all NaNs from the path and
         insert MOVETO commands to skip over them.

        *clip*: if not None, must be a four-tuple (x1, y1, x2, y2)
         defining a rectangle in which to clip the path.

        *quantize*: if None, auto-quantize.  If True, force quantize,
         and if False, don't quantize.

        *simplify*: if True, perform simplification, to remove
         vertices that do not affect the appearance of the path.  If
         False, perform no simplification.  If None, use the
         should_simplify member variable.

        *curves*: If True, curve segments will be returned as curve
         segments.  If False, all curves will be converted to line
         segments.
        """
        vertices = self.vertices
        if not len(vertices):
            return

        codes        = self.codes

        NUM_VERTICES = self.NUM_VERTICES
        MOVETO       = self.MOVETO
        LINETO       = self.LINETO
        CLOSEPOLY    = self.CLOSEPOLY
        STOP         = self.STOP

        vertices, codes = cleanup_path(self, transform, remove_nans, clip,
                                       quantize, simplify, curves)
        len_vertices = len(vertices)

        i = 0
        while i < len_vertices:
            code = codes[i]
            if code == STOP:
                return
            else:
                num_vertices = NUM_VERTICES[int(code) & 0xf]
                curr_vertices = vertices[i:i+num_vertices].flatten()
                yield curr_vertices, code
                i += num_vertices
Exemplo n.º 5
0
    def iter_segments(self,
                      transform=None,
                      remove_nans=True,
                      clip=None,
                      snap=False,
                      stroke_width=1.0,
                      simplify=None,
                      curves=True,
                      sketch=None):
        """
        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.

        Additionally, this method can provide a number of standard
        cleanups and conversions to the path.

        *transform*: if not None, the given affine transformation will
         be applied to the path.

        *remove_nans*: if True, will remove all NaNs from the path and
         insert MOVETO commands to skip over them.

        *clip*: if not None, must be a four-tuple (x1, y1, x2, y2)
         defining a rectangle in which to clip the path.

        *snap*: if None, auto-snap to pixels, to reduce
         fuzziness of rectilinear lines.  If True, force snapping, and
         if False, don't snap.

        *stroke_width*: the width of the stroke being drawn.  Needed
         as a hint for the snapping algorithm.

        *simplify*: if True, perform simplification, to remove
         vertices that do not affect the appearance of the path.  If
         False, perform no simplification.  If None, use the
         should_simplify member variable.

        *curves*: If True, curve segments will be returned as curve
         segments.  If False, all curves will be converted to line
         segments.

        *sketch*: If not None, must be a 3-tuple of the form
         (scale, length, randomness), representing the sketch
         parameters.
        """
        vertices = self.vertices
        if not len(vertices):
            return

        codes = self.codes

        NUM_VERTICES = self.NUM_VERTICES
        MOVETO = self.MOVETO
        LINETO = self.LINETO
        CLOSEPOLY = self.CLOSEPOLY
        STOP = self.STOP

        vertices, codes = cleanup_path(self, transform, remove_nans, clip,
                                       snap, stroke_width, simplify, curves,
                                       sketch)
        len_vertices = len(vertices)

        i = 0
        while i < len_vertices:
            code = codes[i]
            if code == STOP:
                return
            else:
                num_vertices = NUM_VERTICES[int(code) & 0xf]
                curr_vertices = vertices[i:i + num_vertices].flatten()
                yield curr_vertices, code
                i += num_vertices
Exemplo n.º 6
0
    def iter_segments(self, transform=None, remove_nans=True, clip=None,
                      snap=False, stroke_width=1.0, simplify=None,
                      curves=True, sketch=None):
        """
        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.

        Additionally, this method can provide a number of standard
        cleanups and conversions to the path.

        *transform*: if not None, the given affine transformation will
         be applied to the path.

        *remove_nans*: if True, will remove all NaNs from the path and
         insert MOVETO commands to skip over them.

        *clip*: if not None, must be a four-tuple (x1, y1, x2, y2)
         defining a rectangle in which to clip the path.

        *snap*: if None, auto-snap to pixels, to reduce
         fuzziness of rectilinear lines.  If True, force snapping, and
         if False, don't snap.

        *stroke_width*: the width of the stroke being drawn.  Needed
         as a hint for the snapping algorithm.

        *simplify*: if True, perform simplification, to remove
         vertices that do not affect the appearance of the path.  If
         False, perform no simplification.  If None, use the
         should_simplify member variable.

        *curves*: If True, curve segments will be returned as curve
         segments.  If False, all curves will be converted to line
         segments.

        *sketch*: If not None, must be a 3-tuple of the form
         (scale, length, randomness), representing the sketch
         parameters.
        """
        vertices = self.vertices
        if not len(vertices):
            return

        codes        = self.codes

        NUM_VERTICES = self.NUM_VERTICES
        MOVETO       = self.MOVETO
        LINETO       = self.LINETO
        CLOSEPOLY    = self.CLOSEPOLY
        STOP         = self.STOP

        vertices, codes = cleanup_path(self, transform, remove_nans, clip,
                                       snap, stroke_width, simplify, curves,
                                       sketch)
        len_vertices = len(vertices)

        i = 0
        while i < len_vertices:
            code = codes[i]
            if code == STOP:
                return
            else:
                num_vertices = NUM_VERTICES[int(code) & 0xf]
                curr_vertices = vertices[i:i+num_vertices].flatten()
                yield curr_vertices, code
                i += num_vertices