
Java Platform 1.2 Beta 4 

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: INNER  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object  +java.awt.Polygon
Polygon
class encapsulates a description of a
closed, twodimensional 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

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 a point to this polygon. 
boolean  contains(double x,
double y,
double w,
double h)
Test if the interior of the Shape entirely contains the given set of rectangular coordinates. 
boolean  contains(double x,
double y)
Test if a given coordinate is inside the boundary of the shape. 
boolean  contains(int x,
int y)
Determines whether the specified point is contained by this polygon. 
boolean  contains(Point p)
Determines whether the specified point is inside the Polygon. 
boolean  contains(Point2D p)
Test if a given Point is inside the boundary of the shape. 
boolean  contains(Rectangle2D r)
Test if the interior of the Shape entirely contains the given Rectangle. 
Rectangle  getBoundingBox()
Deprecated. As of JDK version 1.1, replaced by getBounds() . 
Rectangle  getBounds()
Gets the bounding box of this polygon. 
Rectangle2D  getBounds2D()
Return the high precision bounding box of the shape. 
PathIterator  getPathIterator(AffineTransform at,
double flatness)
Return an iterator object that iterates along the boundary of the shape and provides access to a flattened view of the geometry of the outline of the shape. 
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. 
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)
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  translate(int deltaX,
int deltaY)
Translates the vertices 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
public int[] xpoints
public int[] ypoints
protected Rectangle bounds
Constructor Detail 
public Polygon()
public Polygon(int[] xpoints, int[] ypoints, int npoints)
xpoints
 an array of x coordinates.
ypoints
 an array of y coordinates.
npoints
 the total number of points in the polygon.npoints
is negative.Method Detail 
public void translate(int deltaX, int deltaY)
deltaX
along the
x axis and by deltaY
along the
y axis.
deltaX
 the amount to translate along the x axis
deltaY
 the amount to translate along the y axispublic void addPoint(int x, int y)
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 x coordinate of the point.
y
 the y coordinate of the point.getBounds()
,
contains(java.awt.Point)
public Rectangle getBounds()
public Rectangle getBoundingBox()
getBounds()
.public boolean contains(Point p)
p
 the point to be testedpublic boolean contains(int x, int y)
(The contains
method is based on code by
Hanpeter van Vliet [hvvliet@inter.nl.net].)
x
 the x coordinate of the point to be tested.
y
 the y coordinate of the point to be tested.true
if the point (x, y)
is contained by this polygon;
false
otherwise.public boolean inside(int x, int y)
contains(int, int)
.public Rectangle2D getBounds2D()
public boolean contains(double x, double y)
public boolean contains(Point2D p)
public boolean intersects(double x, double y, double w, double h)
public boolean intersects(Rectangle2D r)
public boolean contains(double x, double y, double w, double h)
public boolean contains(Rectangle2D r)
public PathIterator getPathIterator(AffineTransform at)
at
 an optional AffineTransform to be applied to the
coordinates as they are returned in the iteration, or null
if the untransformed coordinates are desired.public PathIterator getPathIterator(AffineTransform at, double flatness)
flatness
parameter which specifies ?REMIND?.
An optional affine transform can be specified in which case
the coordinates returned in the iteration will be transformed
accordingly.
at
 an optional AffineTransform to be applied to the
coordinates as they are returned in the iteration, or null
if the untransformed coordinates are desired.
flatness
 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.

Java Platform 1.2 Beta 4 

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: INNER  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 