Java Platform 1.2
Beta 4

Class java.awt.Polygon

java.lang.Object
  |
  +--java.awt.Polygon

public class Polygon
extends Object
implements Shape, Serializable
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 (xy) 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 (xy) points are joined by a line segment that closes the polygon.

Since:
JDK1.0
See Also:
Serialized Form

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

npoints

public int npoints
The total number of points.

xpoints

public int[] xpoints
The array of x coordinates.

ypoints

public int[] ypoints
The array of y coordinates.

bounds

protected Rectangle bounds
Constructor Detail

Polygon

public Polygon()
Creates an empty polygon.

Polygon

public Polygon(int[] xpoints,
               int[] ypoints,
               int npoints)
Constructs and initializes a polygon from the specified parameters.
Parameters:
xpoints - an array of x coordinates.
ypoints - an array of y coordinates.
npoints - the total number of points in the polygon.
Throws:
NegativeArraySizeException - if the value of npoints is negative.
Method Detail

translate

public void translate(int deltaX,
                      int deltaY)
Translates the vertices by deltaX along the x axis and by deltaY along the y axis.
Parameters:
deltaX - the amount to translate along the x axis
deltaY - the amount to translate along the y axis
Since:
JDK1.1

addPoint

public void addPoint(int x,
                     int y)
Appends a point to this 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.

Parameters:
x - the x coordinate of the point.
y - the y coordinate of the point.
See Also:
getBounds(), contains(java.awt.Point)

getBounds

public Rectangle getBounds()
Gets the bounding box of this polygon. The bounding box is the smallest rectangle whose sides are parallel to the x and y axes of the coordinate space, and that can completely contain the polygon.
Specified by:
getBounds in interface Shape
Returns:
a rectangle that defines the bounds of this polygon.
Since:
JDK1.1

getBoundingBox

public Rectangle getBoundingBox()
Deprecated. As of JDK version 1.1, replaced by getBounds().

contains

public boolean contains(Point p)
Determines whether the specified point is inside the Polygon. Uses an even-odd insideness rule (also known as an alternating rule).
Parameters:
p - the point to be tested

contains

public boolean contains(int x,
                        int y)
Determines whether the specified point is contained by this polygon.

(The contains method is based on code by Hanpeter van Vliet [hvvliet@inter.nl.net].)

Parameters:
x - the x coordinate of the point to be tested.
y - the y coordinate of the point to be tested.
Returns:
true if the point (xy) is contained by this polygon; false otherwise.
Since:
JDK1.1

inside

public boolean inside(int x,
                      int y)
Deprecated. As of JDK version 1.1, replaced by contains(int, int).

getBounds2D

public Rectangle2D getBounds2D()
Return the high precision bounding box of the shape.
Specified by:
getBounds2D in interface Shape

contains

public boolean contains(double x,
                        double y)
Test if a given coordinate is inside the boundary of the shape.
Specified by:
contains in interface Shape

contains

public boolean contains(Point2D p)
Test if a given Point is inside the boundary of the shape.
Specified by:
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.
Specified by:
intersects in interface Shape

intersects

public boolean intersects(Rectangle2D r)
Test if the interior of the Shape intersects the interior of a given Rectangle.
Specified by:
intersects in interface Shape

contains

public 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.
Specified by:
contains in interface Shape

contains

public boolean contains(Rectangle2D r)
Test if the interior of the Shape entirely contains the given Rectangle.
Specified by:
contains 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. An optional affine transform can be specified in which case the coordinates returned in the iteration will be transformed accordingly.
Specified by:
getPathIterator in interface Shape
Parameters:
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.

getPathIterator

public 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. Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types will be returned by the iterator. The amount of subdivision of the curved segments is controlled by the 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.
Specified by:
getPathIterator in interface Shape
Parameters:
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

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.
This documentation was generated with a post-Beta4 version of Javadoc.