public final class GeneralPath extends Object implements Shape
A general geometric path, consisting of any number of subpaths constructed
out of straight lines and cubic or quadratic Bezier curves. The inside of the
curve is defined for drawing purposes by a winding rule. Either the
WIND_EVEN_ODD
or WIND_NON_ZERO
winding rule can be chosen.
The WIND_EVEN_ODD
winding rule defines a point as inside a path if:
A ray from the point towards infinity in an arbitrary direction intersects
the path an odd number of times. Points A and C in the
image are considered to be outside the path. (both intersect twice) Point
B intersects once, and is inside.
The WIND_NON_ZERO
winding rule defines a point as inside a path if:
The path intersects the ray in an equal number of opposite directions. Point
A
in the image is outside (one intersection in the 'up' direction,
one in the 'down' direction) Point B in the image is inside (one
intersection 'down') Point C in the image is inside (two intersections in the
'down' direction)
Note: This description and image were copied from the GNU classpath docs). License here http://www.gnu.org/licenses/licenses.html#FDL
Modifier and Type | Field and Description |
---|---|
static int |
WIND_EVEN_ODD
Same constant as
PathIterator.WIND_EVEN_ODD |
static int |
WIND_NON_ZERO
Same constant as
PathIterator.WIND_NON_ZERO |
Constructor and Description |
---|
GeneralPath()
Constructs a GeneralPath with the default (
WIND_NON_ZERO )
winding rule and initial capacity (10). |
GeneralPath(int rule)
Constructs a GeneralPath with a specific winding rule and the default
initial capacity (10).
|
GeneralPath(int rule,
int initialCapacity)
Constructs a GeneralPath with a specific winding rule and the initial
capacity.
|
GeneralPath(Shape shape)
Constructs a GeneralPath from an arbitrary shape object.
|
Modifier and Type | Method and Description |
---|---|
void |
append(PathIterator path,
boolean connect)
Appends the segments of a PathIterator to this GeneralPath.
|
void |
append(Shape shape,
boolean connect)
Appends the segments of a Shape to the path.
|
void |
arc(double x,
double y,
double w,
double h,
double startAngle,
double sweepAngle)
Draws an elliptical arc on the path given the provided bounds.
|
void |
arc(double x,
double y,
double w,
double h,
double startAngle,
double sweepAngle,
boolean joinPath)
Draws an elliptical arc on the path given the provided bounds.
|
void |
arc(float x,
float y,
float w,
float h,
float startAngle,
float sweepAngle)
Draws an elliptical arc on the path given the provided bounds.
|
void |
arc(float x,
float y,
float w,
float h,
float startAngle,
float sweepAngle,
boolean joinPath)
Draws an elliptical arc on the path given the provided bounds.
|
void |
arcTo(double cX,
double cY,
double endX,
double endY)
Adds an arc to the path.
|
void |
arcTo(double cX,
double cY,
double endX,
double endY,
boolean clockwise)
Adds an arc to the path.
|
void |
arcTo(float cX,
float cY,
float endX,
float endY)
Adds an arc to the path.
|
void |
arcTo(float cX,
float cY,
float endX,
float endY,
boolean clockwise)
Adds an arc to the path.
|
void |
closePath()
Closes the current subpath by drawing a line back to the point of the
last moveTo, unless the path is already closed.
|
boolean |
contains(float x,
float y)
Checks if the given point is contained in the current shape.
|
boolean |
contains(int x,
int y)
{Checks if the shape contains the given point.}
|
static GeneralPath |
createFromPool()
Creates a new GeneralPath from an object Pool.
|
Shape |
createTransformedShape(Transform m)
Returns a shape formed by transforming the current shape with the provided
transform.
|
void |
curveTo(double x1,
double y1,
double x2,
double y2,
double x3,
double y3) |
void |
curveTo(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Appends a cubic Bezier curve to the current path.
|
boolean |
equals(Shape shape,
Transform t) |
Rectangle |
getBounds()
Returns the path's bounding box.
|
void |
getBounds(Rectangle out)
Sets the coordinates of the provided rectangle to the bounding box of this path.
|
float[] |
getBounds2D()
Returns the path's bounding box, in float precision.
|
void |
getBounds2D(float[] out)
Sets the 4-element array to the bounding box coordinates of the path.
|
float[] |
getCurrentPoint()
Returns the current appending point of the path.
|
void |
getCurrentPoint(float[] point)
Sets the coordinates of the given point to the current point in the path.
|
PathIterator |
getPathIterator()
{Gets an iterator to walk all of the path segments of the shape.}
|
PathIterator |
getPathIterator(Transform m)
{Gets an iterator where all points are transformed by the provided transform.}
|
void |
getPoints(float[] out)
Returns a copy of the points in this path.
|
int |
getPointsSize()
Returns the number of points in this path.
|
void |
getTypes(byte[] out)
Returns a copy of the types (aka path commands) in this path.
|
int |
getTypesSize()
Returns the number of path commands in this path.
|
int |
getWindingRule()
Returns the path's current winding rule.
|
boolean |
intersect(int x,
int y,
int w,
int h) |
boolean |
intersect(Rectangle rect)
Sets the current path to the intersection of itself and the provided rectangle.
|
void |
intersect(Shape shape)
Resets this path to be the intersection of itself with the given shape.
|
Shape |
intersection(Rectangle rect)
{Returns the shape formed by the intersection of this shape and the provided
rectangle.}
|
static boolean |
isConvexPolygon(float[] xPoints,
float[] yPoints)
Checks to see if the set of points form a convex polygon.
|
static boolean |
isConvexPolygon(int[] xPoints,
int[] yPoints) |
boolean |
isPolygon()
Checks to see if this path forms a polygon.
|
boolean |
isRectangle()
Checks to see if this path is a rectangle.
|
void |
lineTo(double x,
double y) |
void |
lineTo(float x,
float y)
Appends a straight line to the current path.
|
void |
moveTo(double x,
double y) |
void |
moveTo(float x,
float y)
Adds a new point to a path.
|
void |
quadTo(double x1,
double y1,
double x2,
double y2) |
void |
quadTo(float x1,
float y1,
float x2,
float y2)
Appends a quadratic Bezier curve to the current path.
|
static void |
recycle(GeneralPath p)
Returns a GeneralPath to the reusable object pool for GeneralPaths.
|
void |
reset()
Resets the path.
|
void |
setPath(GeneralPath p,
Transform t)
Sets this path to be identical to the provided path
p with the given
Transform t applied to it. |
void |
setRect(Rectangle r,
Transform t)
Sets this path to be a rectangle with the provided bounds, but with
the given transform applied to it.
|
void |
setShape(Shape s,
Transform t)
Sets this path to be a copy of the provided shape, but with the provided
transform applied to it.
|
void |
setWindingRule(int rule)
Sets the path's winding rule, which controls which areas are considered
'inside' or 'outside' the path on drawing.
|
String |
toString()
Returns a string representation of the object.
|
void |
transform(Transform m)
Transforms the current path in place using the given transform.
|
public static final int WIND_EVEN_ODD
PathIterator.WIND_EVEN_ODD
public static final int WIND_NON_ZERO
PathIterator.WIND_NON_ZERO
public GeneralPath()
WIND_NON_ZERO
)
winding rule and initial capacity (10).public GeneralPath(int rule)
rule
- The winding rule. One of WIND_NON_ZERO
and
WIND_EVEN_ODD
WIND_NON_ZERO
,
WIND_EVEN_ODD
public GeneralPath(int rule, int initialCapacity)
rule
- The winding rule. (WIND_NON_ZERO
or
WIND_EVEN_ODD
).initialCapacity
- the inital capacity, in path segmentspublic GeneralPath(Shape shape)
shape
- public static void recycle(GeneralPath p)
p
- The path to recycle.createFromPool()
public static GeneralPath createFromPool()
You should return this object back to the pool when you are done
using the recycle(com.codename1.ui.geom.GeneralPath)
method.
public boolean isPolygon()
public int getTypesSize()
public int getPointsSize()
public void getTypes(byte[] out)
out
- An array to copy the path commands into.public void getPoints(float[] out)
out
- An array to copy the points into.public String toString()
Object
public void setWindingRule(int rule)
WIND_EVEN_ODD
for an even-odd winding rule, or
WIND_NON_ZERO
for a non-zero winding rule.rule
- the rule. (WIND_NON_ZERO
or WIND_EVEN_ODD
).public int getWindingRule()
WIND_NON_ZERO
or WIND_EVEN_ODD
public void moveTo(double x, double y)
public void moveTo(float x, float y)
x
- the x-coordinate.y
- the y-coordinate.public void lineTo(double x, double y)
public void lineTo(float x, float y)
x
- x coordinate of the line endpoint.y
- y coordinate of the line endpoint.public void quadTo(double x1, double y1, double x2, double y2)
public void quadTo(float x1, float y1, float x2, float y2)
x1
- x coordinate of the control pointy1
- y coordinate of the control pointx2
- x coordinate of the curve endpoint.y2
- y coordinate of the curve endpoint.public void curveTo(double x1, double y1, double x2, double y2, double x3, double y3)
public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
x1
- x coordinate of the first control pointy1
- y coordinate of the first control pointx2
- x coordinate of the second control pointy2
- y coordinate of the second control pointx3
- x coordinate of the curve endpoint.y3
- y coordinate of the curve endpoint.public void arc(float x, float y, float w, float h, float startAngle, float sweepAngle)
x
- Left x coord of bounding rect.y
- Top y coordof bounding rect.w
- Width of bounding rect.h
- Height of bounding rect.startAngle
- Start angle on ellipse in radians. Counter-clockwise from 3-o'clock.sweepAngle
- Sweep angle in radians. Counter-clockwise.public void arc(float x, float y, float w, float h, float startAngle, float sweepAngle, boolean joinPath)
x
- Left x coord of bounding rect.y
- Top y coordof bounding rect.w
- Width of bounding rect.h
- Height of bounding rect.startAngle
- Start angle on ellipse in radians. Counter-clockwise from 3-o'clock.sweepAngle
- Sweep angle in radians. Counter-clockwise.joinPath
- If true, then this will join the arc to the existing path with a line.public void arc(double x, double y, double w, double h, double startAngle, double sweepAngle)
x
- Left x coord of bounding rect.y
- Top y coordof bounding rect.w
- Width of bounding rect.h
- Height of bounding rect.startAngle
- Start angle on ellipse in radians. Counter-clockwise from 3-o'clock.sweepAngle
- Sweep angle in radians. Counter-clockwise.public void arc(double x, double y, double w, double h, double startAngle, double sweepAngle, boolean joinPath)
x
- Left x coord of bounding rect.y
- Top y coordof bounding rect.w
- Width of bounding rect.h
- Height of bounding rect.startAngle
- Start angle on ellipse in radians. Counter-clockwise from 3-o'clock.sweepAngle
- Sweep angle in radians. Counter-clockwise.joinPath
- If true then this will join the arc to the existing path with a line.public void arcTo(float cX, float cY, float endX, float endY)
Note: The arc is drawn counter-clockwise around the center point. See arcTo(double, double, double, double, boolean)
to draw clockwise.
cX
- The x-coordinate of the oval center.cY
- The y-coordinate of the oval center.endX
- The end X coordinate.endY
- The end Y coordinate.public void arcTo(float cX, float cY, float endX, float endY, boolean clockwise)
cX
- The x-coordinate of the oval center.cY
- The y-coordinate of the oval center.endX
- The end X coordinate.endY
- The end Y coordinate.clockwise
- If true, the arc is drawn clockwise around the center point.public void arcTo(double cX, double cY, double endX, double endY)
Note: The arc is drawn counter-clockwise around the center point. See arcTo(double, double, double, double, boolean)
to draw clockwise.
cX
- The x-coordinate of the oval center.cY
- The y-coordinate of the oval center.endX
- The end X coordinate.endY
- The end Y coordinate.public void arcTo(double cX, double cY, double endX, double endY, boolean clockwise)
cX
- The x-coordinate of the oval center.cY
- The y-coordinate of the oval center.endX
- The end X coordinate.endY
- The end Y coordinate.clockwise
- If true, the arc is drawn clockwise around the center point.public void closePath()
public void append(Shape shape, boolean connect)
shape
- the shape (null not permitted).connect
- whether to connect the new shape to the existing path.public void append(PathIterator path, boolean connect)
PathIterator.SEG_MOVETO
segment of the appended path
is changed into a PathIterator.SEG_LINETO
segment.path
- the PathIterator specifying which segments shall be appended
(null not permitted).connect
- true for substituting the initial
PathIterator.SEG_MOVETO
segment by a
PathIterator.SEG_LINETO
, or false for not performing any
substitution. If this GeneralPath
is currently empty, connect is
assumed to be false, thus leaving the initial
PathIterator.SEG_MOVETO
unchanged.public float[] getCurrentPoint()
[x,y]
representing x
and y
coordinate of the current appending point of the path..public void getCurrentPoint(float[] point)
point
- Out parameter. Will be filled with the coords of the current point.public void reset()
public float[] getBounds2D()
getBounds2D
in interface Shape
[x, y, width, height]
.public void getBounds2D(float[] out)
out
- 4-element float[] array.public Rectangle getBounds()
public void getBounds(Rectangle out)
out
- public boolean isRectangle()
isRectangle
in interface Shape
public PathIterator getPathIterator()
getPathIterator
in interface Shape
public PathIterator getPathIterator(Transform m)
Note: If Transform.isSupported()
is false, then using this iterator will throw a Runtime Exception.
getPathIterator
in interface Shape
public Shape createTransformedShape(Transform m)
Note: If Transform.isSupported()
is false, this may throw a RuntimeException.
m
- The transform to be used to transform the shape.public void setPath(GeneralPath p, Transform t)
p
with the given
Transform t
applied to it.p
- The path to copy.t
- The transform to apply to all points in the path.public void setRect(Rectangle r, Transform t)
r
- Rectangle to copy.t
- The transform to apply to the points in in r
.public void setShape(Shape s, Transform t)
s
- The shape to copy.t
- The transform to apply to all points in the shape.public boolean intersect(Rectangle rect)
rect
- The rectangle to intersect with this path.rect
intersects the current path. False otherwise. If there is no intersection, the
path will be reset to be empty.public boolean intersect(int x, int y, int w, int h)
public void transform(Transform m)
m
- The transform to apply to the path.public void intersect(Shape shape)
Rectangle
s are current supported. If you pass any other
shape, it will throw a RuntimeException.
Note: If com.codename1.ui.TransformisSupported
is false, this will throw a Runtime Exception
shape
- The shape to intersect with the current shape.public Shape intersection(Rectangle rect)
intersection
in interface Shape
rect
- A rectangle with which to form an intersection.public boolean contains(float x, float y)
x
- The x coordinate to checky
- The y coordinate to checkpublic boolean contains(int x, int y)
public static boolean isConvexPolygon(float[] xPoints, float[] yPoints)
xPoints
- The x coordinates of the polygon.yPoints
- The y coordinates of the polygon.public static boolean isConvexPolygon(int[] xPoints, int[] yPoints)