|
|||||||||
| Home >> All >> java >> awt >> [ geom overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.awt.geom
Class GeneralPath

java.lang.Objectjava.awt.geom.GeneralPath
- All Implemented Interfaces:
- java.lang.Cloneable, java.awt.Shape
- public final class GeneralPath
- extends java.lang.Object
- implements java.awt.Shape, java.lang.Cloneable
- extends java.lang.Object
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 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 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 outside (two intersections ’down’)
- Since:
- 1.2
| Nested Class Summary | |
private static class |
GeneralPath.GeneralPathIterator
A PathIterator that iterates over the segments of a GeneralPath. |
| Field Summary | |
private static double |
BIG_VALUE
A big number, but not so big it can't survive a few float operations |
(package private) int |
index
The next available index into points. |
private static int |
INIT_SIZE
Initial size if not specified. |
(package private) int |
rule
The winding rule. |
private int |
subpath
The index of the most recent moveto point, or null. |
(package private) byte[] |
types
The path type in points. |
static int |
WIND_EVEN_ODD
Same constant as WIND_EVEN_ODD 55 . |
static int |
WIND_NON_ZERO
Same constant as PathIterator.WIND_NON_ZERO. |
(package private) float[] |
xpoints
The list of all points seen. |
(package private) float[] |
ypoints
|
| Constructor Summary | |
GeneralPath()
Constructs a GeneralPath with the default (NON_ZERO) winding rule and initial capacity (20). |
|
GeneralPath(int rule)
Constructs a GeneralPath with a specific winding rule and the default initial capacity (20). |
|
GeneralPath(int rule,
int capacity)
Constructs a GeneralPath with a specific winding rule and the initial capacity. |
|
GeneralPath(java.awt.Shape s)
Constructs a GeneralPath from an arbitrary shape object. |
|
| Method Summary | |
void |
append(PathIterator iter,
boolean connect)
Appends the segments of a PathIterator to this GeneralPath. |
void |
append(java.awt.Shape s,
boolean connect)
Appends the segments of a Shape to the path. |
java.lang.Object |
clone()
Creates a new shape of the same run-time type with the same contents as this one. |
void |
closePath()
Closes the current subpath by drawing a line back to the point of the last moveTo. |
boolean |
contains(double x,
double y)
Evaluates if a point is within the GeneralPath, The NON_ZERO winding rule is used, regardless of the set winding rule. |
boolean |
contains(double x,
double y,
double w,
double h)
Evaluates if a rectangle is completely contained within the path. |
boolean |
contains(Point2D p)
Evaluates if a Point2D is within the GeneralPath, The NON_ZERO winding rule is used, regardless of the set winding rule. |
boolean |
contains(Rectangle2D r)
Evaluates if a rectangle is completely contained within the path. |
java.awt.Shape |
createTransformedShape(AffineTransform xform)
Creates a transformed version of the path. |
void |
curveTo(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Appends a cubic Bezier curve to the current path. |
private void |
ensureSize(int size)
Helper method - ensure the size of the data arrays, otherwise, reallocate new ones twice the size |
private int |
evaluateCrossings(double x,
double y,
boolean neg,
boolean useYaxis,
double distance)
Helper method - evaluates the number of intersections on an axis from the point (x,y) to the point (x,y+distance) or (x+distance,y). |
private int |
getAxisIntersections(double x,
double y,
boolean useYaxis,
double distance)
Helper method - Get the total number of intersections from (x,y) along a given axis, within a given distance. |
java.awt.Rectangle |
getBounds()
Returns the path’s bounding box. |
Rectangle2D |
getBounds2D()
Returns the path’s bounding box, in float precision |
Point2D |
getCurrentPoint()
Returns the current appending point of the path. |
PathIterator |
getPathIterator(AffineTransform at)
Creates a PathIterator for iterating along the segments of the path. |
PathIterator |
getPathIterator(AffineTransform at,
double flatness)
Creates a new FlatteningPathIterator for the path |
private int |
getWindingNumber(double x,
double y)
Helper method - returns the winding number of a point. |
int |
getWindingRule()
Returns the path’s current winding rule. |
boolean |
intersects(double x,
double y,
double w,
double h)
Evaluates if a rectangle intersects the path. |
boolean |
intersects(Rectangle2D r)
Evaluates if a Rectangle2D intersects the path. |
void |
lineTo(float x,
float y)
Appends a straight line to the current path. |
void |
moveTo(float x,
float y)
Adds a new point to a path. |
void |
quadTo(float x1,
float y1,
float x2,
float y2)
Appends a quadratic Bezier curve to the current path. |
void |
reset()
Resets the path. |
void |
setWindingRule(int rule)
Sets the path’s winding rule, which controls which areas are considered ’inside’ or ’outside’ the path on drawing. |
void |
transform(AffineTransform xform)
Applies a transform to the path. |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
WIND_EVEN_ODD
public static final int WIND_EVEN_ODD
- Same constant as
WIND_EVEN_ODD55 .- See Also:
- Constant Field Values
WIND_NON_ZERO
public static final int WIND_NON_ZERO
- Same constant as
PathIterator.WIND_NON_ZERO.- See Also:
- Constant Field Values
INIT_SIZE
private static final int INIT_SIZE
- Initial size if not specified.
- See Also:
- Constant Field Values
BIG_VALUE
private static final double BIG_VALUE
- A big number, but not so big it can't survive a few float operations
- See Also:
- Constant Field Values
rule
int rule
- The winding rule.
This is package-private to avoid an accessor method.
types
byte[] types
- The path type in points. Note that xpoints[index] and ypoints[index] maps
to types[index]; the control points of quad and cubic paths map as
well but are ignored.
This is package-private to avoid an accessor method.
xpoints
float[] xpoints
- The list of all points seen. Since you can only append floats, it makes
sense for these to be float[]. I have no idea why Sun didn't choose to
allow a general path of double precision points.
Note: Storing x and y coords seperately makes for a slower transforms,
But it speeds up and simplifies box-intersection checking a lot.
These are package-private to avoid accessor methods.
ypoints
float[] ypoints
subpath
private int subpath
- The index of the most recent moveto point, or null.
index
int index
- The next available index into points.
This is package-private to avoid an accessor method.
| Constructor Detail |
GeneralPath
public GeneralPath()
- Constructs a GeneralPath with the default (NON_ZERO)
winding rule and initial capacity (20).
GeneralPath
public GeneralPath(int rule)
- Constructs a GeneralPath with a specific winding rule
and the default initial capacity (20).
GeneralPath
public GeneralPath(int rule,
int capacity)
- Constructs a GeneralPath with a specific winding rule
and the initial capacity. The initial capacity should be
the approximate number of path segments to be used.
GeneralPath
public GeneralPath(java.awt.Shape s)
- Constructs a GeneralPath from an arbitrary shape object.
The Shapes PathIterator path and winding rule will be used.
| Method Detail |
moveTo
public void moveTo(float x,
float y)
- Adds a new point to a path.
lineTo
public void lineTo(float x,
float y)
- Appends a straight line to the current path.
quadTo
public void quadTo(float x1,
float y1,
float x2,
float y2)
- Appends a quadratic Bezier curve to the current path.
curveTo
public void curveTo(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
- Appends a cubic Bezier curve to the current path.
closePath
public void closePath()
- Closes the current subpath by drawing a line
back to the point of the last moveTo.
append
public void append(java.awt.Shape s, boolean connect)
- Appends the segments of a Shape to the path. If
connectis true, the new path segments are connected to the existing one with a line. The winding rule of the Shape is ignored.
append
public void append(PathIterator iter, boolean connect)
- Appends the segments of a PathIterator to this GeneralPath.
Optionally, the initial
PathIterator.SEG_MOVETO55 segment of the appended path is changed into aPathIterator.SEG_LINETO55 segment.
getWindingRule
public int getWindingRule()
- Returns the path’s current winding rule.
setWindingRule
public void setWindingRule(int rule)
- Sets the path’s winding rule, which controls which areas are
considered ’inside’ or ’outside’ the path
on drawing. Valid rules are WIND_EVEN_ODD for an even-odd winding rule,
or WIND_NON_ZERO for a non-zero winding rule.
getCurrentPoint
public Point2D getCurrentPoint()
- Returns the current appending point of the path.
reset
public void reset()
- Resets the path. All points and segments are destroyed.
transform
public void transform(AffineTransform xform)
- Applies a transform to the path.
createTransformedShape
public java.awt.Shape createTransformedShape(AffineTransform xform)
- Creates a transformed version of the path.
getBounds
public java.awt.Rectangle getBounds()
- Returns the path’s bounding box.
- Specified by:
getBoundsin interfacejava.awt.Shape
getBounds2D
public Rectangle2D getBounds2D()
- Returns the path’s bounding box, in
floatprecision- Specified by:
getBounds2Din interfacejava.awt.Shape
contains
public boolean contains(double x,
double y)
- Evaluates if a point is within the GeneralPath,
The NON_ZERO winding rule is used, regardless of the
set winding rule.
- Specified by:
containsin interfacejava.awt.Shape
contains
public boolean contains(Point2D p)
- Evaluates if a Point2D is within the GeneralPath,
The NON_ZERO winding rule is used, regardless of the
set winding rule.
- Specified by:
containsin interfacejava.awt.Shape
contains
public boolean contains(double x,
double y,
double w,
double h)
- Evaluates if a rectangle is completely contained within the path.
This method will return false in the cases when the box
intersects an inner segment of the path.
(i.e.: The method is accurate for the EVEN_ODD winding rule)
- Specified by:
containsin interfacejava.awt.Shape
contains
public boolean contains(Rectangle2D r)
- Evaluates if a rectangle is completely contained within the path.
This method will return false in the cases when the box
intersects an inner segment of the path.
(i.e.: The method is accurate for the EVEN_ODD winding rule)
- Specified by:
containsin interfacejava.awt.Shape
intersects
public boolean intersects(double x,
double y,
double w,
double h)
- Evaluates if a rectangle intersects the path.
- Specified by:
intersectsin interfacejava.awt.Shape
intersects
public boolean intersects(Rectangle2D r)
- Evaluates if a Rectangle2D intersects the path.
- Specified by:
intersectsin interfacejava.awt.Shape
getPathIterator
public PathIterator getPathIterator(AffineTransform at)
- Creates a PathIterator for iterating along the segments of the path.
- Specified by:
getPathIteratorin interfacejava.awt.Shape
getPathIterator
public PathIterator getPathIterator(AffineTransform at, double flatness)
- Creates a new FlatteningPathIterator for the path
- Specified by:
getPathIteratorin interfacejava.awt.Shape
clone
public java.lang.Object clone()
- Creates a new shape of the same run-time type with the same contents
as this one.
- Since:
- 1.2
ensureSize
private void ensureSize(int size)
- Helper method - ensure the size of the data arrays,
otherwise, reallocate new ones twice the size
getAxisIntersections
private int getAxisIntersections(double x,
double y,
boolean useYaxis,
double distance)
- Helper method - Get the total number of intersections from (x,y) along
a given axis, within a given distance.
getWindingNumber
private int getWindingNumber(double x,
double y)
- Helper method - returns the winding number of a point.
evaluateCrossings
private int evaluateCrossings(double x,
double y,
boolean neg,
boolean useYaxis,
double distance)
- Helper method - evaluates the number of intersections on an axis from
the point (x,y) to the point (x,y+distance) or (x+distance,y).
|
|||||||||
| Home >> All >> java >> awt >> [ geom overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
java.awt.geom.GeneralPath