geomerative
Class RPolygon

java.lang.Object
  extended by geomerative.RGeomElem
      extended by geomerative.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 to perform binary operations (difference, xor, union and intersection) on polygons.


Field Summary
 RContour[] contours
          Array of RContour objects holding the contours of the polygon.
static int defaultDetail
           
 int type
           
 
Fields inherited from class geomerative.RGeomElem
COMMAND, CONTOUR, GROUP, height, MESH, name, POLYGON, SHAPE, SUBSHAPE, TRISTRIP, UNKNOWN, width
 
Constructor Summary
RPolygon()
          Create an empty polygon.
RPolygon(RContour newcontour)
          Create a new polygon given a contour.
RPolygon(RPoint[] points)
          Create a new polygon given an array of points.
RPolygon(RPolygon p)
          Make a copy of the given polygon.
 
Method Summary
 void addClose()
           
 void addContour()
          Add an empty contour to the polygon.
 void addContour(RContour c)
          Add a new contour to the polygon.
 void addContour(RPoint[] points)
          Add a new contour to the polygon given an array of points.
 void addPoint(float x, float y)
          Add a new point to the current contour.
 void addPoint(int indContour, float x, float y)
          Add a new point to the selected contour.
 void addPoint(int indContour, RPoint p)
          Add a new point to the selected contour.
 void addPoint(RPoint p)
          Add a new point to the current contour.
 boolean contains(RPoint p)
           
 int countContours()
          Use this method to count the number of contours in the polygon.
static RPolygon createCircle(float radius)
           
static RPolygon createCircle(float x, float y, float radius)
           
static RPolygon createCircle(float x, float y, float radius, int detail)
          Use this method to create a new circle polygon.
static RPolygon createCircle(float radius, int detail)
           
static RPolygon createRectangle(float w, float h)
           
static RPolygon createRectangle(float x, float y, float w, float h)
          Use this method to create a new rectangle polygon.
static RPolygon createRing(float radiusBig, float radiusSmall)
           
static RPolygon createRing(float x, float y, float radiusBig, float radiusSmall)
           
static RPolygon createRing(float x, float y, float radiusBig, float radiusSmall, int detail)
          Use this method to create a new ring polygon.
static RPolygon createRing(float radiusBig, float radiusSmall, int detail)
           
static RPolygon createStar(float x, float y, float radiusBig, float radiusSmall, int spikes)
          Use this method to create a new starform polygon.
static RPolygon createStar(float radiusBig, float radiusSmall, int spikes)
           
 RPolygon diff(RPolygon p)
          Use this method to get the difference of the given polygon with the polygon passed as atribute.
 void draw(processing.core.PApplet g)
           
 void draw(processing.core.PGraphics g)
          Use this method to draw the polygon.
 float getArea()
          Use this method to get the area covered by the polygon.
 RPoint getCentroid()
          Use this method to get the centroid of the element.
 RPoint[] getHandles()
          Use this to return the points of the polygon.
 RPoint[][] getHandlesInPaths()
           
 RPoint getPoint(float t)
           
 RPoint[] getPoints()
          Use this to return the points of the polygon.
 RPoint[][] getPointsInPaths()
           
 RPoint getTangent(float t)
           
 RPoint[] getTangents()
           
 RPoint[][] getTangentsInPaths()
           
 int getType()
          Use this method to get the type of element this is.
 RPolygon intersection(RPolygon p)
          Use this method to get the intersection of the given polygon with the polygon passed as atribute.
 boolean isHole()
          Return true if this polygon is a hole.
 void print()
           
 void setContour(int indContour)
          Use this method to set the current contour to which append points.
 RMesh toMesh()
          Use this method to create a new mesh from a given polygon.
 RPolygon toPolygon()
           
 RShape toShape()
           
 RPolygon union(RPolygon p)
          Use this method to get the union of the given polygon with the polygon passed as atribute.
 RPolygon update()
          Use this method to get a rebuilt version of a given polygon by removing extra points and solving intersecting contours or holes.
 RPolygon xor(RPolygon p)
          Use this method to get the xor of the given polygon with the polygon passed as atribute.
 
Methods inherited from class geomerative.RGeomElem
centerIn, centerIn, centerIn, contains, contains, containsBounds, containsHandles, draw, getBottomLeft, getBottomRight, getBounds, getBoundsPoints, getCenter, getCenteringTransf, getCenteringTransf, getCenteringTransf, getCurveLength, getCurveLengths, getHeight, getOrigHeight, getOrigWidth, getStyle, getTopLeft, getTopRight, getWidth, getX, getY, intersects, intersects, intersectsBounds, intersectsHandles, isIn, isIn, rotate, rotate, rotate, scale, scale, scale, scale, scale, scale, setAlpha, setAlpha, setAlpha, setFill, setFill, setFill, setFillAlpha, setFillAlpha, setName, setStroke, setStroke, setStroke, setStrokeAlpha, setStrokeAlpha, setStrokeCap, setStrokeJoin, setStrokeWeight, setStrokeWeight, setStyle, shear, skewX, skewY, transform, transform, transform, translate, translate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 of the newly created 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 countours 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

print

public void print()
Overrides:
print in class RGeomElem

toPolygon

public RPolygon toPolygon()
Overrides:
toPolygon in class RGeomElem

toShape

public RShape toShape()
Specified by:
toShape in class RGeomElem

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 the given polygon with the polygon passed as atribute.

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 the given polygon with the polygon passed as atribute.

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 the given polygon with the polygon passed as atribute.

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 of the given polygon with the polygon passed as atribute.

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

getPoint

public RPoint getPoint(float t)
Specified by:
getPoint in class RGeomElem

getTangent

public RPoint getTangent(float t)
Specified by:
getTangent in class RGeomElem

getTangents

public RPoint[] getTangents()
Specified by:
getTangents in class RGeomElem

getPointsInPaths

public RPoint[][] getPointsInPaths()
Specified by:
getPointsInPaths in class RGeomElem

getHandlesInPaths

public RPoint[][] getHandlesInPaths()
Specified by:
getHandlesInPaths in class RGeomElem

getTangentsInPaths

public RPoint[][] getTangentsInPaths()
Specified by:
getTangentsInPaths in class RGeomElem

contains

public boolean contains(RPoint p)
Specified by:
contains in class RGeomElem

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.


Geomerative by Ricard Marxer, http://www.ricardmarxer.com/geomerative/