Package geomerative
Class RShape
- java.lang.Object
-
- geomerative.RGeomElem
-
- geomerative.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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
adapt(RShape shp)
void
adapt(RShape shp, float wght, float lngthOffset)
Use this method to adapt a group of of figures to a shape.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.void
addBezierTo(RPoint p1, RPoint p2, RPoint p3)
void
addChild()
void
addChild(RShape s)
void
addClose()
void
addLineTo(float endx, float endy)
Use this method to add a new lineTo command to the current path.void
addLineTo(RPoint p)
void
addMoveTo(float endx, float endy)
Use this method to add a new moveTo command to the shape.void
addMoveTo(RPoint p)
void
addPath()
void
addPath(RPath s)
Use this method to create a new path.void
addQuadTo(float cp1x, float cp1y, float endx, float endy)
Use this method to add a new quadTo command to the current path.void
addQuadTo(RPoint p1, RPoint p2)
void
addShape(RShape s)
Use this method to add a new shape.boolean
contains(float x, float y)
Use this to return a specific tangent on the curve.boolean
contains(RPoint p)
Use this to return a specific tangent on the curve.int
countChildren()
int
countPaths()
Use this method to count the number of paths in the shape.static RShape
createCircle(float x, float y, float d)
static RShape
createEllipse(float x, float y, float w, float h)
Use this method to create a new elliptical shape.static RShape
createLine(float x1, float y1, float x2, float y2)
Use this method to create a new line.static RShape
createRectangle(float x, float y, float w, float h)
Use this method to create a new circle shape.static RShape
createRing(float x, float y, float widthBig, float widthSmall)
Use this method to create a new ring polygon.static RShape
createStar(float x, float y, float widthBig, float widthSmall, int spikes)
Use this method to create a new starform polygon.RShape
diff(RShape 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)
RPoint
getCentroid()
Use this method to get the centroid of the element.RShape
getChild(java.lang.String target)
Extracts a shape by its name.RClosest
getClosest(RShape other)
Use this method to get the closest or intersection points of the shape with another shape passed as argument.RPoint[]
getHandles()
Use this to return the start, control and end points of the shape.RPoint[][]
getHandlesInPaths()
RPoint[]
getIntersections(RShape other)
Use this method to get the points of intersection between this shape and another shape passed in as a parameter.RPoint
getPoint(float t)
Use this to return a point on the curve given a certain advancement.RPoint[]
getPoints()
Use this to return the points on the curve of the shape.RPoint[][]
getPointsInPaths()
Use this to return the points of each path of the group.RPoint
getTangent(float t)
Use this to return a point on the curve given a certain advancement.RPoint[]
getTangents()
Use this to return the points on the curve of the shape.RPoint[][]
getTangentsInPaths()
int
getType()
Use this method to get the type of element this is.void
insertHandle(float t)
Use this to insert a split point into the shape.void
insertHandleInPaths(float t)
Use this to insert a split point into each command of the shape.RShape
intersection(RShape p)
Use this method to get the intersection of this polygon with the polygon passed in as a parameter.void
polygonize()
void
print()
void
setPath(int indPath)
Use this method to set the current path.RShape[]
split(float t)
RShape[]
splitPaths(float t)
RMesh
toMesh()
Use this method to create a new mesh from a given polygon.RPolygon
toPolygon()
Use this method to create a new polygon from a given shape.RShape
toShape()
RShape
union(RShape p)
Use this method to get the union of this polygon with the polygon passed in as a parameter.RShape
xor(RShape 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, getArea, 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
-
-
-
-
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 liney1
- y coordinate of the first point of the linex2
- x coordinate of the last point of the liney2
- 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 shapey
- y coordinate of the center of the shapewidthBig
- the outer width of the ring polygonwidthSmall
- 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 polygonwidthSmall
- the inner width of the star polygonspikes
- 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 rectangley
- the y position of the rectanglew
- the width of the rectangleh
- 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 ellipsey
- the y position of the ellipsew
- the width of the ellipseh
- 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 classRGeomElem
- 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.
-
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.
-
toPolygon
public RPolygon toPolygon()
Use this method to create a new polygon from a given shape.
-
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 classRGeomElem
- 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.
-
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.
-
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 classRGeomElem
- 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
-
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 classRGeomElem
- 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 classRGeomElem
- Returns:
- RPoint[], the points returned in an array.
-
getHandlesInPaths
public RPoint[][] getHandlesInPaths()
- Specified by:
getHandlesInPaths
in classRGeomElem
-
getTangentsInPaths
public RPoint[][] getTangentsInPaths()
- Specified by:
getTangentsInPaths
in classRGeomElem
-
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.
-
-