geomerative
Class RPath

java.lang.Object
  extended by geomerative.RGeomElem
      extended by geomerative.RPath

public class RPath
extends RGeomElem

RPath is a reduced interface for creating, holding and drawing contours. Paths are ordered lists of commands (RCommand) which define the outlines of Shapes. Paths can be self-intersecting.


Field Summary
 RCommand[] commands
          Array of RCommand objects holding the commands of the path.
 RPoint lastPoint
          Last point from where to add the next command.
 int type
           
 
Fields inherited from class geomerative.RGeomElem
COMMAND, CONTOUR, GROUP, height, MESH, name, POLYGON, SHAPE, SUBSHAPE, TRISTRIP, UNKNOWN, width
 
Constructor Summary
RPath()
          Create a new empty path.
RPath(float x, float y)
          Create a new path, given the coordinates of the first point.
RPath(RCommand c)
           
RPath(RPath s)
          Copy a path.
RPath(RPoint p)
          Create a new path, given the first point.
RPath(RPoint[] points)
          Create a new path, given an array of points.
 
Method Summary
 void addBezierTo(float cp1x, float cp1y, float cp2x, float cp2y, float endx, float endy)
          Add a new cubic bezier to the path.
 void addBezierTo(RPoint cp1, RPoint cp2, RPoint end)
          Add a new cubic bezier to the path.
 void addClose()
           
 void addCommand(RCommand p)
          Use this method to add new commands to the contour.
 void addLineTo(float endx, float endy)
          Add a new line to the path.
 void addLineTo(RPoint end)
          Add a new line to the path.
 void addQuadTo(float cp1x, float cp1y, float endx, float endy)
          Add a new quadratic bezier to the path.
 void addQuadTo(RPoint cp1, RPoint end)
          Add a new quadratic bezier to the path.
 RClosest closestPoints(RCommand other)
          Use this to find the closest or intersection points between this path and a command.
 RClosest closestPoints(RPath other)
          Use this to return the intersection points between two paths.
 boolean contains(RPoint p)
          Use this to return a specific tangent on the curve.
 int countCommands()
          Use this method to count the number of commands in the contour.
 void draw(processing.core.PApplet g)
           
 void draw(processing.core.PGraphics g)
          Use this method to draw the path.
 RPoint[] getHandles()
          Use this to return the start, control and end points of the path.
 RPoint[][] getHandlesInPaths()
          Use this to return the handles of each path of the path.
 RPoint getPoint(float t)
          Return a specific point on the curve.
 RPoint[] getPoints()
          Use this to return the points on the curve.
 RPoint[][] getPointsInPaths()
          Use this to return the points of each path of the path.
 RPoint getTangent(float t)
          Use this to return a specific tangent on the curve.
 RPoint[] getTangents()
          Use this to return the tangents on the curve.
 RPoint[][] getTangentsInPaths()
          Use this to return the tangents of each path of the path.
 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 path.
 void insertHandleInPaths(float t)
          Use this to insert a split point into each command of the path.
 RPoint[] intersectionPoints(RCommand other)
          Use this to return the intersection points between this path and a command.
 RPoint[] intersectionPoints(RPath other)
          Use this to return the intersection points between two paths.
 void polygonize()
           
 void print()
           
 RPath[] split(float t)
          Use this to split a path into two separate new paths.
 RMesh toMesh()
           
 RPolygon toPolygon()
           
 RShape toShape()
           
 
Methods inherited from class geomerative.RGeomElem
centerIn, centerIn, centerIn, contains, contains, containsBounds, containsHandles, draw, getArea, getBottomLeft, getBottomRight, getBounds, getBoundsPoints, getCenter, getCenteringTransf, getCenteringTransf, getCenteringTransf, getCentroid, 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

commands

public RCommand[] commands
Array of RCommand objects holding the commands of the path.


lastPoint

public RPoint lastPoint
Last point from where to add the next command. Initialized to (0, 0).

Constructor Detail

RPath

public RPath()
Create a new empty path.


RPath

public RPath(RPoint[] points)
Create a new path, given an array of points.

Parameters:
points - the points of the new path

RPath

public RPath(float x,
             float y)
Create a new path, given the coordinates of the first point.

Parameters:
x - x coordinate of the first point of the new path
y - y coordinate of the first point of the new path

RPath

public RPath(RPoint p)
Create a new path, given the first point.

Parameters:
p - first point of the new path

RPath

public RPath(RPath s)
Copy a path.

Parameters:
s - path to be copied

RPath

public RPath(RCommand c)
Method Detail

countCommands

public int countCommands()
Use this method to count the number of commands in the contour.

Returns:
int, the number commands in the contour

getHandles

public RPoint[] getHandles()
Use this to return the start, control and end points of the path. It returns the points in the way of an array of RPoint.

Specified by:
getHandles in class RGeomElem
Returns:
RPoint[], the start, control and end points returned in an array.

getPoints

public RPoint[] getPoints()
Use this to return the points on the curve. It returns the points in the way of an array of RPoint.

Specified by:
getPoints in class RGeomElem
Returns:
RPoint[], the vertices returned in an array.

getPointsInPaths

public RPoint[][] getPointsInPaths()
Use this to return the points of each path of the path. It returns the points in the way of an array of array of RPoint.

Specified by:
getPointsInPaths in class RGeomElem
Returns:
RPoint[], the points returned in an array.

getHandlesInPaths

public RPoint[][] getHandlesInPaths()
Use this to return the handles of each path of the path. It returns the handles in the way of an array of array of RPoint.

Specified by:
getHandlesInPaths in class RGeomElem
Returns:
RPoint[], the handles returned in an array.

getTangentsInPaths

public RPoint[][] getTangentsInPaths()
Use this to return the tangents of each path of the path. It returns the tangents in the way of an array of array of RPoint.

Specified by:
getTangentsInPaths in class RGeomElem
Returns:
RPoint[], the tangents returned in an array.

getTangents

public RPoint[] getTangents()
Use this to return the tangents on the curve. It returns the vectors in the way of an array of RPoint.

Specified by:
getTangents in class RGeomElem
Returns:
RPoint[], the tangent vectors returned in an array.

intersectionPoints

public RPoint[] intersectionPoints(RCommand other)
Use this to return the intersection points between this path and a command. Returns null if no intersection exists.

Returns:
RPoint[], the intersection points returned in an array.

intersectionPoints

public RPoint[] intersectionPoints(RPath other)
Use this to return the intersection points between two paths. Returns null if no intersection exists.

Returns:
RPoint[], the intersection points returned in an array.

closestPoints

public RClosest closestPoints(RCommand other)
Use this to find the closest or intersection points between this path and a command.

Returns:
RPoint[], the intersection points returned in an array.

closestPoints

public RClosest closestPoints(RPath other)
Use this to return the intersection points between two paths. Returns null if no intersection exists.

Returns:
RPoint[], the intersection points returned in an array.

getPoint

public RPoint getPoint(float t)
Return a specific point on the curve. It returns the RPoint for a given advancement parameter t on the curve.

Specified by:
getPoint in class RGeomElem
Parameters:
t - the parameter of advancement on the curve. t must have values between 0 and 1.
Returns:
RPoint, the vertice returned.

getTangent

public RPoint getTangent(float t)
Use this to return a specific tangent on the curve. It returns the RPoint tangent for a given advancement parameter t on the curve.

Specified by:
getTangent in class RGeomElem
Parameters:
t - float, the parameter of advancement on the curve. t must have values between 0 and 1.
Returns:
RPoint, the vertice returned.

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 path. 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 containement..
Returns:
boolean, true if the point is in the path.

insertHandle

public void insertHandle(float t)
Use this to insert a split point into the path.

Parameters:
t - float, 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 path.

Parameters:
t - float, the parameter of advancement on the curve. t must have values between 0 and 1.

split

public RPath[] split(float t)
Use this to split a path into two separate new paths.

Parameters:
t - float, the parameter of advancement on the curve. t must have values between 0 and 1.
Returns:
RPath[], an array of two RPath.

polygonize

public void polygonize()

draw

public void draw(processing.core.PGraphics g)
Use this method to draw the path.

Specified by:
draw in class RGeomElem
Parameters:
g - PGraphics, the graphics object on which to draw the path

draw

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

addCommand

public void addCommand(RCommand p)
Use this method to add new commands to the contour.


addBezierTo

public void addBezierTo(RPoint cp1,
                        RPoint cp2,
                        RPoint end)
Add a new cubic bezier to the path. The first point of the bezier will be the last point added to the path.

Parameters:
cp1 - first control point
cp2 - second control point
end - end point

addBezierTo

public void addBezierTo(float cp1x,
                        float cp1y,
                        float cp2x,
                        float cp2y,
                        float endx,
                        float endy)
Add a new cubic bezier to the path. The first point of the bezier will be the last point added to the path.

Parameters:
cp1x - the x coordinate of the first control point
cp1y - the y coordinate of the first control point
cp2x - the x coordinate of the second control point
cp2y - the y coordinate of the second control point
endx - the x coordinate of the end point
endy - the y coordinate of the end point

addQuadTo

public void addQuadTo(RPoint cp1,
                      RPoint end)
Add a new quadratic bezier to the path. The first point of the bezier will be the last point added to the path.

Parameters:
cp1 - first control point
end - end point

addQuadTo

public void addQuadTo(float cp1x,
                      float cp1y,
                      float endx,
                      float endy)
Add a new quadratic bezier to the path. The first point of the bezier will be the last point added to the path.

Parameters:
cp1x - the x coordinate of the first control point
cp1y - the y coordinate of the first control point
endx - the x coordinate of the end point
endy - the y coordinate of the end point

addLineTo

public void addLineTo(RPoint end)
Add a new line to the path. The first point of the line will be the last point added to the path.

Parameters:
end - end point

addLineTo

public void addLineTo(float endx,
                      float endy)
Add a new line to the path. The first point of the line will be the last point added to the path.

Parameters:
endx - the x coordinate of the end point
endy - the y coordinate of the end point

addClose

public void addClose()

toPolygon

public RPolygon toPolygon()
Overrides:
toPolygon in class RGeomElem

toShape

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

toMesh

public RMesh toMesh()
Overrides:
toMesh in class RGeomElem

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

print

public void print()
Overrides:
print in class RGeomElem


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