|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Polygon
The Polygon
class encapsulates a description of a
closed, two-dimensional region within a coordinate space. This
region is bounded by an arbitrary number of line segments, each of
which is one side of the polygon. Internally, a polygon
comprises of a list of (x, y)
coordinate pairs, where each pair defines a vertex of the
polygon, and two successive pairs are the endpoints of a
line that is a side of the polygon. The first and final
pairs of (x, y) points are joined by a line segment
that closes the polygon.
Field Summary | |
protected Rectangle |
bounds
Bounds of the polygon. |
int |
npoints
The total number of points. |
int[] |
xpoints
The array of x coordinates. |
int[] |
ypoints
The array of y coordinates. |
Constructor Summary | |
Polygon()
Creates an empty polygon. |
|
Polygon(int[] xpoints,
int[] ypoints,
int npoints)
Constructs and initializes a Polygon from the specified
parameters. |
Method Summary | |
void |
addPoint(int x,
int y)
Appends the specified coordinates to this Polygon . |
boolean |
contains(double x,
double y)
Tests if the specified coordinates are inside the boundary of the Shape . |
boolean |
contains(double x,
double y,
double w,
double h)
Tests if the interior of this Polygon entirely
contains the specified set of rectangular coordinates. |
boolean |
contains(int x,
int y)
Determines whether the specified coordinates are contained in this Polygon . |
boolean |
contains(Point p)
Determines whether the specified Point is inside this
Polygon . |
boolean |
contains(Point2D p)
Tests if a specified Point2D is inside the boundary of this
Polygon . |
boolean |
contains(Rectangle2D r)
Tests if the interior of this Polygon entirely
contains the specified Rectangle2D . |
Rectangle |
getBoundingBox()
Deprecated. As of JDK version 1.1, replaced by getBounds() . |
Rectangle |
getBounds()
Gets the bounding box of this Polygon . |
Rectangle2D |
getBounds2D()
Returns the high precision bounding box of the Shape . |
PathIterator |
getPathIterator(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 . |
PathIterator |
getPathIterator(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 . |
boolean |
inside(int x,
int y)
Deprecated. As of JDK version 1.1, replaced by contains(int, int) . |
boolean |
intersects(double x,
double y,
double w,
double h)
Tests if the interior of this Polygon intersects the
interior of a specified set of rectangular coordinates. |
boolean |
intersects(Rectangle2D r)
Tests if the interior of this Polygon intersects the
interior of a specified Rectangle2D . |
void |
translate(int deltaX,
int deltaY)
Translates the vertices of the Polygon by
deltaX along the x axis and by
deltaY along the y axis. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public int npoints
addPoint(int, int)
public int[] xpoints
addPoint(int, int)
public int[] ypoints
addPoint(int, int)
protected Rectangle bounds
getBoundingBox()
,
getBounds()
Constructor Detail |
public Polygon()
public Polygon(int[] xpoints, int[] ypoints, int npoints)
Polygon
from the specified
parameters.xpoints
- an array of x coordinatesypoints
- an array of y coordinatesnpoints
- the total number of points in the
Polygon
npoints
is negative.Method Detail |
public void translate(int deltaX, int 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 void addPoint(int x, int 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, y
- the specified coordinatesgetBounds()
,
contains(java.awt.Point)
public 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
.Rectangle
that defines the bounds of this
Polygon
.public Rectangle getBoundingBox()
getBounds()
.
public boolean contains(Point p)
Point
is inside this
Polygon
. Uses an even-odd insideness rule (also known
as an alternating rule).p
- the specified Point
to be testedtrue
if the Polygon
contains the
Point
; false
otherwise.public boolean contains(int x, int y)
Polygon
.
(The contains
method is based on code by
Hanpeter van Vliet [hvvliet@inter.nl.net].)
x, y
- the specified coordinates to be testedtrue
if this Polygon
contains
the specified coordinates, (x, y);
false
otherwise.public boolean inside(int x, int y)
contains(int, int)
.
public Rectangle2D getBounds2D()
Shape
.Rectangle2D
that precisely
bounds the Shape
.public boolean contains(double x, double y)
Shape
.x, y
- the specified coordinatestrue
if the Shape
contains the
specified coordinates; false
otherwise.public boolean contains(Point2D p)
Point2D
is inside the boundary of this
Polygon
.p
- a specified Point2D
true
if this Polygon
contains the
specified Point2D
; false
otherwise.public boolean intersects(double x, double y, double w, double h)
Polygon
intersects the
interior of a specified set of rectangular coordinates.x, y
- the coordinates of the specified rectangular
shape's top-left cornerw
- the width of the specified rectangular shapeh
- the height of the specified rectangular shapetrue
if the interior of this
Polygon
and the interior of the
specified set of rectangular
coordinates intersect each other;
false
otherwise.public boolean intersects(Rectangle2D r)
Polygon
intersects the
interior of a specified Rectangle2D
.r
- a specified Rectangle2D
true
if this Polygon
and the
interior of the specified Rectangle2D
intersect each other; false
otherwise.public boolean contains(double x, double y, double w, double h)
Polygon
entirely
contains the specified set of rectangular coordinates.x, y
- the coordinate of the top-left corner of the
specified set of rectangular coordinatesw
- the width of the set of rectangular coordinatesh
- the height of the set of rectangular coordinatestrue
if this Polygon
entirely
contains the specified set of rectangular
coordinates; false
otherwise.public boolean contains(Rectangle2D r)
Polygon
entirely
contains the specified Rectangle2D
.r
- the specified Rectangle2D
true
if this Polygon
entirely
contains the specified Rectangle2D
;
false
otherwise.public PathIterator getPathIterator(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.at
- 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 PathIterator getPathIterator(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.at
- 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.
|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |