public abstract class Polygon2D
extends java.lang.Object
implements java.awt.Shape, java.lang.Cloneable
| Modifier and Type | Class and Description |
|---|---|
static class |
Polygon2D.Double
The
Double class defines a polygon with
coordinates stored in double precision floating point. |
static class |
Polygon2D.Float
The
Float class defines a polygon with
coordinates stored in float precision floating point. |
| Modifier and Type | Field and Description |
|---|---|
int |
npoints
The total number of points.
|
| Constructor and Description |
|---|
Polygon2D()
Creates an empty polygon.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.awt.geom.Point2D p) |
abstract void |
addPoint(double x,
double y)
Appends the specified coordinates to this
Polygon. |
abstract boolean |
contains(double x,
double y) |
abstract boolean |
contains(double x,
double y,
double w,
double h) |
boolean |
contains(int x,
int y)
Determines whether the specified coordinates are inside this
Polygon. |
boolean |
contains(java.awt.Point p)
Determines whether the specified
Point is inside this
Polygon. |
boolean |
contains(java.awt.geom.Point2D p) |
boolean |
contains(java.awt.geom.Rectangle2D r) |
java.awt.Rectangle |
getBounds()
Gets the bounding box of this
Polygon. |
abstract java.awt.geom.Rectangle2D |
getBounds2D() |
abstract java.awt.geom.PathIterator |
getPathIterator(java.awt.geom.AffineTransform at)
Returns an iterator object that iterates along the boundary of this
Polygon and provides access to the geometry
of the outline of this Polygon. |
java.awt.geom.PathIterator |
getPathIterator(java.awt.geom.AffineTransform at,
double flatness)
Returns an iterator object that iterates along the boundary of
the
Shape and provides access to the geometry of the
outline of the Shape. |
abstract boolean |
intersects(double x,
double y,
double w,
double h) |
boolean |
intersects(java.awt.geom.Rectangle2D r) |
abstract void |
invalidate()
Invalidates or flushes any internally-cached data that depends
on the vertex coordinates of this
Polygon. |
void |
reset()
Resets this
Polygon object to an empty polygon. |
abstract void |
translate(double deltaX,
double deltaY)
Translates the vertices of the
Polygon by
deltaX along the x axis and by
deltaY along the y axis. |
public int npoints
npoints
represents the number of valid points in this Polygon
and might be less than the number of elements in
xpoints or ypoints.
This value can be NULL.public void reset()
Polygon object to an empty polygon.
The coordinate arrays and the data in them are left untouched
but the number of points is reset to zero to mark the old
vertex data as invalid and to start accumulating new vertex
data at the beginning.
All internally-cached data relating to the old vertices
are discarded.
Note that since the coordinate arrays from before the reset
are reused, creating a new empty Polygon might
be more memory efficient than resetting the current one if
the number of vertices in the new polygon data is significantly
smaller than the number of vertices in the data from before the
reset.Polygon.invalidate()public abstract void invalidate()
Polygon.
This method should be called after any direct manipulation
of the coordinates in the xpoints or
ypoints arrays to avoid inconsistent results
from methods such as getBounds or contains
that might cache data from earlier computations relating to
the vertex coordinates.Polygon.getBounds()public abstract void translate(double deltaX,
double deltaY)
Polygon by
deltaX along the x axis and by
deltaY along the y axis.deltaX - the amount to translate along the X axisdeltaY - the amount to translate along the Y axispublic abstract void addPoint(double x,
double y)
Polygon.
If an operation that calculates the bounding box of this
Polygon has already been performed, such as
getBounds or contains, then this
method updates the bounding box.
x - the specified X coordinatey - the specified Y coordinatePolygon.getBounds(),
Polygon.contains(java.awt.Point)public void add(java.awt.geom.Point2D p)
public java.awt.Rectangle getBounds()
Polygon.
The bounding box is the smallest Rectangle whose
sides are parallel to the x and y axes of the
coordinate space, and can completely contain the Polygon.getBounds in interface java.awt.ShapeRectangle that defines the bounds of this
Polygon.public boolean contains(java.awt.Point p)
Point is inside this
Polygon.p - the specified Point to be testedtrue if the Polygon contains the
Point; false otherwise.contains(double, double)public boolean contains(int x,
int y)
Polygon.
x - the specified X coordinate to be testedy - the specified Y coordinate to be testedtrue if this Polygon contains
the specified coordinates (x,y);
false otherwise.contains(double, double)public abstract java.awt.geom.Rectangle2D getBounds2D()
getBounds2D in interface java.awt.Shapepublic abstract boolean contains(double x,
double y)
contains in interface java.awt.Shapepublic boolean contains(java.awt.geom.Point2D p)
contains in interface java.awt.Shapepublic abstract boolean intersects(double x,
double y,
double w,
double h)
intersects in interface java.awt.Shapepublic boolean intersects(java.awt.geom.Rectangle2D r)
intersects in interface java.awt.Shapepublic abstract boolean contains(double x,
double y,
double w,
double h)
contains in interface java.awt.Shapepublic boolean contains(java.awt.geom.Rectangle2D r)
contains in interface java.awt.Shapepublic abstract java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
Polygon and provides access to the geometry
of the outline of this Polygon. An optional
AffineTransform can be specified so that the coordinates
returned in the iteration are transformed accordingly.getPathIterator in interface java.awt.Shapeat - an optional AffineTransform to be applied to the
coordinates as they are returned in the iteration, or
null if untransformed coordinates are desiredPathIterator object that provides access to the
geometry of this Polygon.public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at,
double flatness)
Shape and provides access to the geometry of the
outline of the Shape. Only SEG_MOVETO, SEG_LINETO, and
SEG_CLOSE point types are returned by the iterator.
Since polygons are already flat, the flatness parameter
is ignored. An optional AffineTransform can be specified
in which case the coordinates returned in the iteration are transformed
accordingly.getPathIterator in interface java.awt.Shapeat - an optional AffineTransform to be applied to the
coordinates as they are returned in the iteration, or
null if untransformed coordinates are desiredflatness - the maximum amount that the control points
for a given curve can vary from colinear before a subdivided
curve is replaced by a straight line connecting the
endpoints. Since polygons are already flat the
flatness parameter is ignored.PathIterator object that provides access to the
Shape object's geometry.