public class Polygon extends Object implements Shape, Serializable
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. This Polygon
is defined with
an even-odd winding rule. See
WIND_EVEN_ODD
for a definition of the even-odd winding rule.
This class's hit-testing methods, which include the
contains
, intersects
and inside
methods, use the insideness definition described in the
Shape
class comments.Shape
,
Serialized FormModifier and Type | Field | Description |
---|---|---|
protected Rectangle |
bounds |
The bounds of this
Polygon . |
int |
npoints |
The total number of points.
|
int[] |
xpoints |
The array of X coordinates.
|
int[] |
ypoints |
The array of Y coordinates.
|
Constructor | Description |
---|---|
Polygon() |
Creates an empty polygon.
|
Polygon(int[] xpoints,
int[] ypoints,
int npoints) |
Constructs and initializes a
Polygon from the specified
parameters. |
Modifier and Type | Method | Description |
---|---|---|
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 , as described by the
definition of insideness. |
boolean |
contains(double x,
double y,
double w,
double h) |
Tests if the interior of the
Shape entirely contains
the specified rectangular area. |
boolean |
contains(int x,
int y) |
Determines whether the specified coordinates are inside this
Polygon . |
boolean |
|