Package geomerative

Class RPath


  • public class RPath
    extends RGeomElem
    RPath is a reduced interface for creating, holding and drawing contours. Paths are ordered lists of commands (RCommand) which define the outlines of shapes. Paths can be self-intersecting.
    • Field Detail

      • type

        public int type
      • commands

        public RCommand[] commands
        Array of RCommand objects holding the commands of the path.
      • lastPoint

        public RPoint lastPoint
        Last point from where to add the next command. Initialized to (0, 0).
    • Constructor Detail

      • RPath

        public RPath()
        Create a new empty path.
      • RPath

        public RPath​(RPoint[] points)
        Create a new path, given an array of points.
        Parameters:
        points - the points of the new path
      • RPath

        public RPath​(float x,
                     float y)
        Create a new path, given the coordinates of the first point.
        Parameters:
        x - x coordinate of the first point of the new path
        y - y coordinate of the first point of the new path
      • RPath

        public RPath​(RPoint p)
        Create a new path, given the first point.
        Parameters:
        p - first point of the new path
      • RPath

        public RPath​(RPath s)
        Copy a path.
        Parameters:
        s - path to be copied
    • Method Detail

      • countCommands

        public int countCommands()
        Use this method to count the number of commands in the contour.
        Returns:
        int, the number commands in the contour
      • getHandles

        public RPoint[] getHandles()
        Use this to return the start, control and end points of the path. It returns the points in the way of an array of RPoint.
        Specified by:
        getHandles in class RGeomElem
        Returns:
        RPoint[], the start, control and end points returned in an array.
      • getPoints

        public RPoint[] getPoints()
        Use this to return the points on the curve. It returns the points in the way of an array of RPoint.
        Specified by:
        getPoints in class RGeomElem
        Returns:
        RPoint[], the vertices returned in an array.
      • getPointsInPaths

        public RPoint[][] getPointsInPaths()
        Use this to return the points of each path of the path. It returns the points in the way of an array of array of RPoint.
        Specified by:
        getPointsInPaths in class RGeomElem
        Returns:
        RPoint[], the points returned in an array.
      • getHandlesInPaths

        public RPoint[][] getHandlesInPaths()
        Use this to return the handles of each path of the path. It returns the handles in the way of an array of array of RPoint.
        Specified by:
        getHandlesInPaths in class RGeomElem
        Returns:
        RPoint[], the handles returned in an array.
      • getTangentsInPaths

        public RPoint[][] getTangentsInPaths()
        Use this to return the tangents of each path of the path. It returns the tangents in the way of an array of array of RPoint.
        Specified by:
        getTangentsInPaths in class RGeomElem
        Returns:
        RPoint[], the tangents returned in an array.
      • getTangents

        public RPoint[] getTangents()
        Use this to return the tangents on the curve. It returns the vectors in the way of an array of RPoint.
        Specified by:
        getTangents in class RGeomElem
        Returns:
        RPoint[], the tangent vectors returned in an array.
      • intersectionPoints

        public RPoint[] intersectionPoints​(RCommand other)
        Use this to return the intersection points between this path and a command. Returns null if no intersection exists.
        Returns:
        RPoint[], the intersection points returned in an array.
      • intersectionPoints

        public RPoint[] intersectionPoints​(RPath other)
        Use this to return the intersection points between two paths. Returns null if no intersection exists.
        Returns:
        RPoint[], the intersection points returned in an array.
      • closestPoints

        public RClosest closestPoints​(RCommand other)
        Use this to find the closest or intersection points between this path and a command.
        Returns:
        RPoint[], the intersection points returned in an array.
      • closestPoints

        public RClosest closestPoints​(RPath other)
        Use this to return the intersection points between two paths. Returns null if no intersection exists.
        Returns:
        RPoint[], the intersection points returned in an array.
      • getPoint

        public RPoint getPoint​(float t)
        Return a specific point on the curve. It returns the RPoint for a given advancement parameter t on the curve.
        Specified by:
        getPoint in class RGeomElem
        Parameters:
        t - the parameter of advancement on the curve. t must have values between 0 and 1.
        Returns:
        RPoint, the vertice returned.
      • getTangent

        public RPoint getTangent​(float t)
        Use this to return a specific tangent on the curve. It returns the RPoint tangent for a given advancement parameter t on the curve.
        Specified by:
        getTangent in class RGeomElem
        Parameters:
        t - float, the parameter of advancement on the curve. t must have values between 0 and 1.
        Returns:
        RPoint, the vertice returned.
      • contains

        public boolean contains​(RPoint p)
        Use this to return a specific tangent on the curve. It returns true if the point passed as a parameter is inside the path. Implementation taken from: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
        Specified by:
        contains in class RGeomElem
        Parameters:
        p - the point for which to test containement..
        Returns:
        boolean, true if the point is in the path.
      • insertHandle

        public void insertHandle​(float t)
        Use this to insert a split point into the path.
        Parameters:
        t - float, the parameter of advancement on the curve. t must have values between 0 and 1.
      • insertHandleInPaths

        public void insertHandleInPaths​(float t)
        Use this to insert a split point into each command of the path.
        Parameters:
        t - float, the parameter of advancement on the curve. t must have values between 0 and 1.
      • split

        public RPath[] split​(float t)
        Use this to split a path into two separate new paths.
        Parameters:
        t - float, the parameter of advancement on the curve. t must have values between 0 and 1.
        Returns:
        RPath[], an array of two RPath.
      • polygonize

        public void polygonize()
      • draw

        public void draw​(processing.core.PGraphics g)
        Use this method to draw the path.
        Specified by:
        draw in class RGeomElem
        Parameters:
        g - PGraphics, the graphics object on which to draw the path
      • draw

        public void draw​(processing.core.PApplet g)
        Specified by:
        draw in class RGeomElem
      • addCommand

        public void addCommand​(RCommand p)
        Use this method to add new commands to the contour.
      • addBezierTo

        public void addBezierTo​(RPoint cp1,
                                RPoint cp2,
                                RPoint end)
        Add a new cubic bezier to the path. The first point of the bezier will be the last point added to the path.
        Parameters:
        cp1 - first control point
        cp2 - second control point
        end - end point
      • addBezierTo

        public void addBezierTo​(float cp1x,
                                float cp1y,
                                float cp2x,
                                float cp2y,
                                float endx,
                                float endy)
        Add a new cubic bezier to the path. The first point of the bezier will be the last point added to the path.
        Parameters:
        cp1x - the x coordinate of the first control point
        cp1y - the y coordinate of the first control point
        cp2x - the x coordinate of the second control point
        cp2y - the y coordinate of the second control point
        endx - the x coordinate of the end point
        endy - the y coordinate of the end point
      • addQuadTo

        public void addQuadTo​(RPoint cp1,
                              RPoint end)
        Add a new quadratic bezier to the path. The first point of the bezier will be the last point added to the path.
        Parameters:
        cp1 - first control point
        end - end point
      • addQuadTo

        public void addQuadTo​(float cp1x,
                              float cp1y,
                              float endx,
                              float endy)
        Add a new quadratic bezier to the path. The first point of the bezier will be the last point added to the path.
        Parameters:
        cp1x - the x coordinate of the first control point
        cp1y - the y coordinate of the first control point
        endx - the x coordinate of the end point
        endy - the y coordinate of the end point
      • addLineTo

        public void addLineTo​(RPoint end)
        Add a new line to the path. The first point of the line will be the last point added to the path.
        Parameters:
        end - end point
      • addLineTo

        public void addLineTo​(float endx,
                              float endy)
        Add a new line to the path. The first point of the line will be the last point added to the path.
        Parameters:
        endx - the x coordinate of the end point
        endy - the y coordinate of the end point
      • addClose

        public void addClose()
      • getType

        public int getType()
        Use this method to get the type of element this is.
        Specified by:
        getType in class RGeomElem
        Returns:
        int, will allways return RGeomElem.POLYGON