Class java.awt.geom.GeneralPath
java.lang.Object
|
+----java.awt.geom.GeneralPath
- public final class GeneralPath
- extends Object
- implements Shape, Cloneable
This class represents a geometric path constructed from straight
lines, quadratic and cubic (Bezier) curves. It can contain multiple
subpaths.
The winding rule specifies how the interior of a path will be
determined. There are two types of winding rules: EVEN_ODD and
NON_ZERO. An EVEN-ODD winding rule means that enclosed regions
of the path alternate between interior and exterior areas as
traversed from the outside of the path towards a point inside
the region. For a NON_ZERO winding rule, we start by conceptually
drawing a ray from a given point to infinity in any direction
and then by examining all of the places where the path intersects
the ray. We now traverse the path in one direction and keep
track of the number of times that the path crosses the ray from
left to right, and the number of times that the path crosses the
ray from right to left. If these numbers are equal, the point
is outside of the path. If they are not equal, the point is
inside.
Field Summary
|
static byte
|
EVEN_ODD
An even-odd winding rule for determining the interior of
a path.
|
static byte
|
NON_ZERO
A non-zero winding rule for determining the interior of a
path.
|
Constructor Summary
|
GeneralPath()
Constructs a new GeneralPath object.
|
GeneralPath(int rule)
Constructs a new GeneralPath object with the specified winding
rule to control operations that require the interior of the
path to be defined.
|
GeneralPath(int rule,
int initialCapacity)
Constructs a new GeneralPath object with the specified winding
rule and the specified initial capacity to store path coordinates.
|
GeneralPath(Shape s)
Constructs a new GeneralPath object from an arbitrary Shape object.
|
Method Summary
|
void
|
append(Shape s,
boolean connect)
Appends the geometry of the specified Shape object to the
path, possibly connecting the geometry to the existing path
segments with a line segment.
|
void
|
append(PathIterator pi,
boolean connect)
Appends the geometry of the specified PathIterator object to the
path, possibly connecting the geometry to the existing path
segments with a line segment.
|
Object
|
clone()
Creates a new object of the same class as this object.
|
void
|
closePath()
Closes the current subpath by drawing a straight line back to
the coordinates of the last moveTo.
|
boolean
|
contains(double x,
double y)
Test if a given coordinate is inside the boundary of the shape.
|
boolean
|
contains(Point2D p)
Test if a given Point is inside the boundary of the shape.
|
boolean
|
contains(double x,
double y,
double w,
double h)
Test if a given coordinate is inside the boundary of the shape.
|
boolean
|
contains(Rectangle2D r)
Test if a given Point is inside the boundary of the shape.
|
Shape
|
createTransformedShape(AffineTransform t)
Returns a new transformed Path.
|
void
|
curveTo(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Adds 3 points to the path by drawing a Bezier curve from the
current coordinates through the third set of specified
coordinates, using the first and second sets of specified
coordinates as Bezier control points.
|
Rectangle
|
getBounds()
Return the bounding box of the shape.
|
Rectangle2D
|
getBounds2D()
Returns the bounding box of the path.
|
Point2D
|
getCurrentPoint()
Returns the most recent point added to the end of the path.
|
PathIterator
|
getPathIterator(AffineTransform at)
Return an iterator object that iterates along the boundary of
the shape and provides access to the geometry of the outline
of the shape.
|
PathIterator
|
getPathIterator(AffineTransform at,
double flatness)
Return an iterator object that iterates along the boundary of
the flattened shape and provides access to the geometry of the
outline of the shape.
|
int
|
getWindingRule()
Returns the fill style winding rule.
|
boolean
|
intersects(double x,
double y,
double w,
double h)
Test if the interior of the Shape intersects the interior of a given
set of rectangular coordinates.
|
boolean
|
intersects(Rectangle2D r)
Test if the interior of the Shape intersects the interior of a given
Rectangle.
|
void
|
lineTo(float x,
float y)
Adds a point to the path by drawing a straight line from the
current coordinates to the new specified coordinates.
|
void
|
moveTo(float x,
float y)
Adds a point to the path by moving to the specified
coordinates.
|
void
|
quadTo(float x1,
float y1,
float x2,
float y2)
Adds 2 points to the path by drawing a Quadratic curve from
the current coordinates through the second set of specified
coordinates, using the first set of specified coordinates as
a quadratic parametric control point.
|
void
|
reset()
Resets the path to empty.
|
void
|
setWindingRule(int rule)
Sets the winding rule for this path to the specified value.
|
void
|
transform(AffineTransform t)
Transforms the geometry of this Path using the specified transform.
|
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
EVEN_ODD
public static final byte EVEN_ODD
- An even-odd winding rule for determining the interior of
a path.
NON_ZERO
public static final byte NON_ZERO
- A non-zero winding rule for determining the interior of a
path.
GeneralPath
public GeneralPath()
- Constructs a new GeneralPath object.
If an operation is performed on this path which requires the
interior of the path to be defined, then the default NON_ZERO
winding rule is used.
- See Also:
- NON_ZERO
GeneralPath
public GeneralPath(int rule)
- Constructs a new GeneralPath object with the specified winding
rule to control operations that require the interior of the
path to be defined.
- Parameters:
rule
- The winding rule.
- See Also:
- EVEN_ODD, NON_ZERO
GeneralPath
public GeneralPath(int rule,
int initialCapacity)
- Constructs a new GeneralPath object with the specified winding
rule and the specified initial capacity to store path coordinates.
This number is an initial guess as to how many coordinates will
be in the path, but the storage will be expanded as needed to
store whatever path segments are added to this path.
- Parameters:
rule
- The winding rule.
initialCapacity
- The estimate for the number of coordinates
in the path.
- See Also:
- EVEN_ODD, NON_ZERO
GeneralPath
public GeneralPath(Shape s)
- Constructs a new GeneralPath object from an arbitrary Shape object.
All of the initial geometry and the winding rule for this path are
taken from the specified Shape object.
moveTo
public void moveTo(float x,
float y)
- Adds a point to the path by moving to the specified
coordinates.
lineTo
public void lineTo(float x,
float y)
- Adds a point to the path by drawing a straight line from the
current coordinates to the new specified coordinates.
quadTo
public void quadTo(float x1,
float y1,
float x2,
float y2)
- Adds 2 points to the path by drawing a Quadratic curve from
the current coordinates through the second set of specified
coordinates, using the first set of specified coordinates as
a quadratic parametric control point.
- Parameters:
x1
- the X coordinate of the first quadratic control point
y1
- the Y coordinate of the first quadratic control point
x2
- the X coordinate of the final endpoint
y2
- the Y coordinate of the final endpoint
curveTo
public void curveTo(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
- Adds 3 points to the path by drawing a Bezier curve from the
current coordinates through the third set of specified
coordinates, using the first and second sets of specified
coordinates as Bezier control points.
- Parameters:
x1
- the X coordinate of the first Bezier control point
y1
- the Y coordinate of the first Bezier control point
x2
- the X coordinate of the second Bezier control point
y2
- the Y coordinate of the second Bezier control point
x3
- the X coordinate of the final endpoint
y3
- the Y coordinate of the final endpoint
closePath
public void closePath()
- Closes the current subpath by drawing a straight line back to
the coordinates of the last moveTo. If the path is already
closed, then this method has no effect.
append
public void append(Shape s,
boolean connect)
- Appends the geometry of the specified Shape object to the
path, possibly connecting the geometry to the existing path
segments with a line segment.
If the connect parameter is true and the path is not empty,
then any initial moveTo in the geometry of the appended Shape
will be turned into a lineTo segment.
If the destination coordinates of such a connecting lineTo
segment match the ending coordinates of a currently open
subpath, then the segment will be omitted as superfluous.
The winding rule of the specified Shape will be ignored
and the appended geometry will be governed by the winding
rule specified for this path.
- Parameters:
s
- the shape whose geometry will be appended to this path
connect
- a boolean to control whether or not to turn an
initial moveTo segment into a lineTo segment to connect the
new geometry to the existing path
append
public void append(PathIterator pi,
boolean connect)
- Appends the geometry of the specified PathIterator object to the
path, possibly connecting the geometry to the existing path
segments with a line segment.
If the connect parameter is true and the path is not empty,
then any initial moveTo in the geometry of the appended Shape
will be turned into a lineTo segment.
If the destination coordinates of such a connecting lineTo
segment match the ending coordinates of a currently open
subpath, then the segment will be omitted as superfluous.
The winding rule of the specified Shape will be ignored
and the appended geometry will be governed by the winding
rule specified for this path.
- Parameters:
s
- the shape whose geometry will be appended to this path
connect
- a boolean to control whether or not to turn an
initial moveTo segment into a lineTo segment to connect the
new geometry to the existing path
getWindingRule
public int getWindingRule()
- Returns the fill style winding rule.
setWindingRule
public void setWindingRule(int rule)
- Sets the winding rule for this path to the specified value.
getCurrentPoint
public Point2D getCurrentPoint()
- Returns the most recent point added to the end of the path.
- Returns:
- a Point object containing the ending coordinate of the
path or null if there are no points in the path.
reset
public void reset()
- Resets the path to empty. The append position is set back to the
beginning of the path and all coordinates and point types are
forgotten.
transform
public void transform(AffineTransform t)
- Transforms the geometry of this Path using the specified transform.
The geometry is transformed in place permanently changing the
boundary defined by this object.
- Parameters:
t
- The matrix used to transform the area.
createTransformedShape
public Shape createTransformedShape(AffineTransform t)
- Returns a new transformed Path.
getBounds
public Rectangle getBounds()
- Return the bounding box of the shape.
- Implements:
- getBounds in interface Shape
getBounds2D
public Rectangle2D getBounds2D()
- Returns the bounding box of the path.
- Implements:
- getBounds2D in interface Shape
contains
public boolean contains(double x,
double y)
- Test if a given coordinate is inside the boundary of the shape.
- Implements:
- contains in interface Shape
contains
public boolean contains(Point2D p)
- Test if a given Point is inside the boundary of the shape.
- Implements:
- contains in interface Shape
contains
public boolean contains(double x,
double y,
double w,
double h)
- Test if a given coordinate is inside the boundary of the shape.
- Implements:
- contains in interface Shape
contains
public boolean contains(Rectangle2D r)
- Test if a given Point is inside the boundary of the shape.
- Implements:
- contains in interface Shape
intersects
public boolean intersects(double x,
double y,
double w,
double h)
- Test if the interior of the Shape intersects the interior of a given
set of rectangular coordinates.
- Implements:
- intersects in interface Shape
intersects
public boolean intersects(Rectangle2D r)
- Test if the interior of the Shape intersects the interior of a given
Rectangle.
- Implements:
- intersects in interface Shape
getPathIterator
public PathIterator getPathIterator(AffineTransform at)
- Return an iterator object that iterates along the boundary of
the shape and provides access to the geometry of the outline
of the shape.
- Implements:
- getPathIterator in interface Shape
getPathIterator
public PathIterator getPathIterator(AffineTransform at,
double flatness)
- Return an iterator object that iterates along the boundary of
the flattened shape and provides access to the geometry of the
outline of the shape.
- Implements:
- getPathIterator in interface Shape
clone
public Object clone()
- Creates a new object of the same class as this object.
- Returns:
- a clone of this instance.
- Throws:
- OutOfMemoryError - if there is not enough memory.
- Overrides:
- clone in class Object
- See Also:
- Cloneable
Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.