Package geomerative

Class RPolygon


  • public class RPolygon
    extends RGeomElem
    RPolygon is a reduced interface for creating, holding and drawing complex polygons. Polygons are groups of one or more contours (RContour). This interface allows us to perform binary operations (difference, xor, union and intersection) on polygons.
    • Field Detail

      • type

        public int type
      • defaultDetail

        public static int defaultDetail
      • contours

        public RContour[] contours
        Array of RContour objects holding the contours of the polygon.
    • Constructor Detail

      • RPolygon

        public RPolygon​(RPolygon p)
        Make a copy of the given polygon.
        Parameters:
        p - the object of which to make a copy
      • RPolygon

        public RPolygon​(RPoint[] points)
        Create a new polygon given an array of points.
        Parameters:
        points - the points for the new polygon.
      • RPolygon

        public RPolygon​(RContour newcontour)
        Create a new polygon given a contour.
        Parameters:
        newcontour - the contour for the new polygon.
      • RPolygon

        public RPolygon()
        Create an empty polygon.
    • Method Detail

      • createCircle

        public static RPolygon createCircle​(float x,
                                            float y,
                                            float radius,
                                            int detail)
        Use this method to create a new circle polygon.
        Parameters:
        radius - the radius of the circle
        detail - the number of vertices of the polygon
        Returns:
        RPolygon, the circular polygon newly created
      • createCircle

        public static RPolygon createCircle​(float radius,
                                            int detail)
      • createCircle

        public static RPolygon createCircle​(float x,
                                            float y,
                                            float radius)
      • createCircle

        public static RPolygon createCircle​(float radius)
      • createRectangle

        public static RPolygon createRectangle​(float x,
                                               float y,
                                               float w,
                                               float h)
        Use this method to create a new rectangle polygon.
        Parameters:
        x - the upper-left corner x coordinate
        y - the upper-left corner y coordinate
        w - the width
        h - the height
        Returns:
        RPolygon, the circular polygon newly created
      • createRectangle

        public static RPolygon createRectangle​(float w,
                                               float h)
      • createStar

        public static RPolygon createStar​(float x,
                                          float y,
                                          float radiusBig,
                                          float radiusSmall,
                                          int spikes)
        Use this method to create a new starform polygon.
        Parameters:
        radiusBig - the outter radius of the star polygon
        radiusSmall - the inner radius of the star polygon
        spikes - the amount of spikes on the star polygon
        Returns:
        RPolygon, the starform polygon newly created
      • createStar

        public static RPolygon createStar​(float radiusBig,
                                          float radiusSmall,
                                          int spikes)
      • createRing

        public static RPolygon createRing​(float x,
                                          float y,
                                          float radiusBig,
                                          float radiusSmall,
                                          int detail)
        Use this method to create a new ring polygon.
        Parameters:
        radiusBig - the outter radius of the ring polygon
        radiusSmall - the inner radius of the ring polygon
        detail - the number of vertices on each contour of the ring
        Returns:
        RPolygon, the ring polygon newly created
      • createRing

        public static RPolygon createRing​(float radiusBig,
                                          float radiusSmall,
                                          int detail)
      • createRing

        public static RPolygon createRing​(float x,
                                          float y,
                                          float radiusBig,
                                          float radiusSmall)
      • createRing

        public static RPolygon createRing​(float radiusBig,
                                          float radiusSmall)
      • getCentroid

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

        public int countContours()
        Use this method to count the number of contours in the polygon.
        Returns:
        int the number contours in the polygon
      • addContour

        public void addContour​(RContour c)
        Add a new contour to the polygon.
        Parameters:
        c - the contour to be added
      • addContour

        public void addContour()
        Add an empty contour to the polygon.
      • addContour

        public void addContour​(RPoint[] points)
        Add a new contour to the polygon given an array of points.
        Parameters:
        points - the points of the new contour to be added
      • setContour

        public void setContour​(int indContour)
        Use this method to set the current contour to which append points.
      • addPoint

        public void addPoint​(RPoint p)
        Add a new point to the current contour.
        Parameters:
        p - the point to be added
      • addPoint

        public void addPoint​(float x,
                             float y)
        Add a new point to the current contour.
        Parameters:
        x - the x coordinate of the point to be added
        y - the y coordinate of the point to be added
      • addPoint

        public void addPoint​(int indContour,
                             RPoint p)
        Add a new point to the selected contour.
        Parameters:
        indContour - the index of the contour to which the point will be added
        p - the point to be added
      • addPoint

        public void addPoint​(int indContour,
                             float x,
                             float y)
        Add a new point to the selected contour.
        Parameters:
        indContour - the index of the contour to which the point will be added
        x - the x coordinate of the point to be added
        y - the y coordinate of the point to be added
      • 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 polygon
      • getHandles

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

        public RPoint[] getPoints()
        Use this to return the points of the polygon. It returns the points in the way of an array of RPoint.
        Specified by:
        getPoints in class RGeomElem
        Returns:
        RPoint[], the points returned in an array.
      • 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
      • getArea

        public float getArea()
        Use this method to get the area covered by the polygon.
        Overrides:
        getArea in class RGeomElem
        Returns:
        float, the area covered by the polygon
      • draw

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

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

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

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

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

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

        public RPolygon update()
        Use this method to get a rebuilt version of a given polygon by removing extra points and solving intersecting contours or holes.
        Returns:
        RPolygon, the updated polygon
      • isHole

        public boolean isHole()
        Return true if this polygon is a hole. Holes are assumed to be inner polygons of a more complex polygon.
        Throws:
        java.lang.IllegalStateException - if called on a complex polygon.