Package geomerative
Class RPolygon
- java.lang.Object
-
- geomerative.RGeomElem
-
- 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 us to perform binary operations (difference, xor, union and intersection) on polygons.
-
-
Field Summary
Fields Modifier and Type Field Description RContour[]
contours
Array of RContour objects holding the contours of the polygon.static int
defaultDetail
int
type
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 between this polygon and the polygon passed in as a parameter.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 this polygon with the polygon passed in as a parameter.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 this polygon with the polygon passed in as a parameter.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 this polygon with the polygon passed in as a parameter.-
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
-
-
-
-
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 circledetail
- 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 coordinatey
- the upper-left corner y coordinatew
- the widthh
- 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 polygonradiusSmall
- the inner radius of the star polygonspikes
- 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 polygonradiusSmall
- the inner radius of the ring polygondetail
- 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 classRGeomElem
- 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 addedy
- 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 addedp
- 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 addedx
- the x coordinate of the point to be addedy
- 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.
-
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 classRGeomElem
- 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.
-
getType
public int getType()
Use this method to get the type of element this is.
-
getArea
public float getArea()
Use this method to get the area covered by the polygon.
-
draw
public void draw(processing.core.PGraphics g)
Use this method to draw the polygon.
-
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
-
getTangent
public RPoint getTangent(float t)
- Specified by:
getTangent
in classRGeomElem
-
getTangents
public RPoint[] getTangents()
- Specified by:
getTangents
in classRGeomElem
-
getPointsInPaths
public RPoint[][] getPointsInPaths()
- Specified by:
getPointsInPaths
in classRGeomElem
-
getHandlesInPaths
public RPoint[][] getHandlesInPaths()
- Specified by:
getHandlesInPaths
in classRGeomElem
-
getTangentsInPaths
public RPoint[][] getTangentsInPaths()
- Specified by:
getTangentsInPaths
in classRGeomElem
-
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.
-
-