Package geomerative

Class RShape


  • public class RShape
    extends RGeomElem
    RShape is a reduced interface for creating, holding and drawing complex shapes. Shapes are groups of one or more paths (RPath). Shapes can be selfintersecting and can contain holes. This interface also allows you to transform shapes into polygons by segmenting the curves forming the shape.
    • Field Detail

      • type

        public int type
      • paths

        public RPath[] paths
        Array of RPath objects holding the paths of the polygon.
      • children

        public RShape[] children
    • Constructor Detail

      • RShape

        public RShape()
        Use this method to create a new empty shape.
      • RShape

        public RShape​(RPath newpath)
      • RShape

        public RShape​(RPath[] newpaths)
      • RShape

        public RShape​(RPoint[][] points)
      • RShape

        public RShape​(RShape s)
    • Method Detail

      • createLine

        public static RShape createLine​(float x1,
                                        float y1,
                                        float x2,
                                        float y2)
        Use this method to create a new line.
        Parameters:
        x1 - x coordinate of the first point of the line
        y1 - y coordinate of the first point of the line
        x2 - x coordinate of the last point of the line
        y2 - y coordinate of the last point of the line
        Returns:
        RShape, the ring polygon newly created
      • createRing

        public static RShape createRing​(float x,
                                        float y,
                                        float widthBig,
                                        float widthSmall)
        Use this method to create a new ring polygon.
        Parameters:
        x - x coordinate of the center of the shape
        y - y coordinate of the center of the shape
        widthBig - the outer width of the ring polygon
        widthSmall - the inner width of the ring polygon
        Returns:
        RShape, the ring polygon newly created
      • createStar

        public static RShape createStar​(float x,
                                        float y,
                                        float widthBig,
                                        float widthSmall,
                                        int spikes)
        Use this method to create a new starform polygon.
        Parameters:
        widthBig - the outer width of the star polygon
        widthSmall - the inner width of the star polygon
        spikes - the amount of spikes on the star polygon
        Returns:
        RShape, the starform polygon newly created
      • createRectangle

        public static RShape createRectangle​(float x,
                                             float y,
                                             float w,
                                             float h)
        Use this method to create a new circle shape.
        Parameters:
        x - the x position of the rectangle
        y - the y position of the rectangle
        w - the width of the rectangle
        h - the height of the rectangle
        Returns:
        RShape, the rectangular shape just created
      • createEllipse

        public static RShape createEllipse​(float x,
                                           float y,
                                           float w,
                                           float h)
        Use this method to create a new elliptical shape.
        Parameters:
        x - the x position of the ellipse
        y - the y position of the ellipse
        w - the width of the ellipse
        h - the height of the ellipse
        Returns:
        RShape, the elliptical shape just created
      • createCircle

        public static RShape createCircle​(float x,
                                          float y,
                                          float d)
      • getChild

        public RShape getChild​(java.lang.String target)
        Extracts a shape by its name. The shape is returned as an RShape object, or null is returned if no shape with the name has been found.
        Returns:
        RShape or null, the target shape or null if not found
      • getCentroid

        public RPoint getCentroid()
        Use this method to get the centroid of the element.
        Overrides:
        getCentroid in class RGeomElem
        Returns:
        RPoint, the centroid point of the element
      • countPaths

        public int countPaths()
        Use this method to count the number of paths in the shape.
      • countChildren

        public int countChildren()
      • addShape

        public void addShape​(RShape s)
        Use this method to add a new shape. The paths of the shape we are adding will simply be added to the current shape.
        Parameters:
        s - RShape, the shape to be added.
      • addPath

        public void addPath​(RPath s)
        Use this method to create a new path. The first point of the new path will be set to (0,0). Use addMoveTo ( ) in order to add a new path with a different first point.
        Parameters:
        s - the path to be added.
      • addPath

        public void addPath()
      • addChild

        public void addChild()
      • addChild

        public void addChild​(RShape s)
      • setPath

        public void setPath​(int indPath)
        Use this method to set the current path.
      • addMoveTo

        public void addMoveTo​(float endx,
                              float endy)
        Use this method to add a new moveTo command to the shape. The command moveTo acts different to normal commands, in order to make a better analogy to its borthers classes Polygon and Mesh. MoveTo creates a new path in the shape. It's similar to adding a new contour to a polygon.
        Parameters:
        endx - the x coordinate of the first point for the new path.
        endy - the y coordinate of the first point for the new path.
      • addMoveTo

        public void addMoveTo​(RPoint p)
      • addLineTo

        public void addLineTo​(float endx,
                              float endy)
        Use this method to add a new lineTo command to the current path. This will add a line from the last point added to the point passed as argument.
        Parameters:
        endx - the x coordinate of the ending point of the line.
        endy - the y coordinate of the ending point of the line.
      • addLineTo

        public void addLineTo​(RPoint p)
      • addQuadTo

        public void addQuadTo​(float cp1x,
                              float cp1y,
                              float endx,
                              float endy)
        Use this method to add a new quadTo command to the current path. This will add a quadratic bezier from the last point added with the control and ending points passed as arguments.
        Parameters:
        cp1x - the x coordinate of the control point of the bezier.
        cp1y - the y coordinate of the control point of the bezier.
        endx - the x coordinate of the ending point of the bezier.
        endy - the y coordinate of the ending point of the bezier.
      • addQuadTo

        public void addQuadTo​(RPoint p1,
                              RPoint p2)
      • addBezierTo

        public void addBezierTo​(float cp1x,
                                float cp1y,
                                float cp2x,
                                float cp2y,
                                float endx,
                                float endy)
        Use this method to add a new bezierTo command to the current path. This will add a cubic bezier from the last point added with the control and ending points passed as arguments.
        Parameters:
        cp1x - the x coordinate of the first control point of the bezier.
        cp1y - the y coordinate of the first control point of the bezier.
        cp2x - the x coordinate of the second control point of the bezier.
        cp2y - the y coordinate of the second control point of the bezier.
        endx - the x coordinate of the ending point of the bezier.
        endy - the y coordinate of the ending point of the bezier.
      • addClose

        public void addClose()
      • toMesh

        public RMesh toMesh()
        Use this method to create a new mesh from a given polygon.
        Overrides:
        toMesh in class RGeomElem
        Returns:
        RMesh, the mesh made of tristrips resulting of a tesselation of the polygonization followed by tesselation of the shape.
      • toPolygon

        public RPolygon toPolygon()
        Use this method to create a new polygon from a given shape.
        Overrides:
        toPolygon in class RGeomElem
        Returns:
        RPolygon, the polygon resulting of the segmentation of the commands in each path.
      • polygonize

        public void polygonize()
      • intersection

        public RShape intersection​(RShape p)
        Use this method to get the intersection of this polygon with the polygon passed in as a parameter.
        Parameters:
        p - RShape, the polygon with which to perform the intersection
        Returns:
        RShape, the intersection of the two polygons
      • union

        public RShape union​(RShape p)
        Use this method to get the union of this polygon with the polygon passed in as a parameter.
        Parameters:
        p - RShape, the polygon with which to perform the union
        Returns:
        RShape, the union of the two polygons
      • xor

        public RShape xor​(RShape p)
        Use this method to get the xor of this polygon with the polygon passed in as a parameter.
        Parameters:
        p - RShape, the polygon with which to perform the xor
        Returns:
        RShape, the xor of the two polygons
      • diff

        public RShape diff​(RShape p)
        Use this method to get the difference between this polygon and the polygon passed in as a parameter.
        Parameters:
        p - RShape, the polygon with which to perform the difference
        Returns:
        RShape, the difference of the two polygons
      • getHandles

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

        public RPoint getPoint​(float t)
        Use this to return a point on the curve given a certain advancement. It returns the point as an RPoint.
        Specified by:
        getPoint in class RGeomElem
        Returns:
        RPoint[], the point on the curve.
      • getPoints

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

        public RPoint getTangent​(float t)
        Use this to return a point on the curve given a certain advancement. It returns the point as an RPoint.
        Specified by:
        getTangent in class RGeomElem
        Returns:
        RPoint[], the point on the curve.
      • contains

        public boolean contains​(float x,
                                float y)
        Use this to return a specific tangent on the curve. It returns true if the point passed as a parameter is inside the shape. Implementation taken from: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
        Parameters:
        x - the X coordinate of the point for which to test containment.
        y - the Y coordinate of the point for which to test containment.
        Returns:
        boolean, true if the point is in the path.
      • 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 shape. 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 containment.
        Returns:
        boolean, true if the point is in the path.
      • getTangents

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

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

        public RShape[] splitPaths​(float t)
      • insertHandle

        public void insertHandle​(float t)
        Use this to insert a split point into the shape.
        Parameters:
        t - 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 shape.
        Parameters:
        t - the parameter of advancement on the curve. t must have values between 0 and 1.
      • split

        public RShape[] split​(float t)
      • getIntersections

        public RPoint[] getIntersections​(RShape other)
        Use this method to get the points of intersection between this shape and another shape passed in as a parameter.
        Parameters:
        other - the path with which to check for intersections
      • getClosest

        public RClosest getClosest​(RShape other)
        Use this method to get the closest or intersection points of the shape with another shape passed as argument.
        Parameters:
        other - the path with which to check for intersections
      • adapt

        public void adapt​(RShape shp,
                          float wght,
                          float lngthOffset)
                   throws java.lang.RuntimeException
        Use this method to adapt a group of of figures to a shape.
        Parameters:
        shp - the path to which to adapt
        Throws:
        java.lang.RuntimeException
      • adapt

        public void adapt​(RShape shp)
                   throws java.lang.RuntimeException
        Throws:
        java.lang.RuntimeException
      • 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.SHAPE
      • draw

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

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