|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Polygon
public class Polygon
This class represents a polygon, a closed, two-dimensional region in a coordinate space. The region is bounded by an arbitrary number of line segments, between (x,y) coordinate vertices. The polygon has even-odd winding, meaning that a point is inside the shape if it crosses the boundary an odd number of times on the way to infinity.
There are some public fields; if you mess with them in an inconsistent manner, it is your own fault when you get NullPointerException, ArrayIndexOutOfBoundsException, or invalid results. Also, this class is not threadsafe.
Field Summary | |
---|---|
protected Rectangle |
bounds
The bounding box of this polygon. |
int |
npoints
This total number of endpoints. |
int[] |
xpoints
The array of X coordinates of endpoints. |
int[] |
ypoints
The array of Y coordinates of endpoints. |
Constructor Summary | |
---|---|
Polygon()
Initializes an empty polygon. |
|
Polygon(int[] xpoints,
int[] ypoints,
int npoints)
Create a new polygon with the specified endpoints. |
Method Summary | |
---|---|
void |
addPoint(int x,
int y)
Adds the specified endpoint to the polygon. |
boolean |
contains(double x,
double y)
Tests whether or not the specified point is inside this polygon. |
boolean |
contains(double x,
double y,
double w,
double h)
Test if a high-precision rectangle lies completely in the shape. |
boolean |
contains(int x,
int y)
Tests whether or not the specified point is inside this polygon. |
boolean |
contains(Point p)
Tests whether or not the specified point is inside this polygon. |
boolean |
contains(Point2D p)
Tests whether or not the specified point is inside this polygon. |
boolean |
contains(Rectangle2D r)
Test if a high-precision rectangle lies completely in the shape. |
Rectangle |
getBoundingBox()
Deprecated. use getBounds() instead |
Rectangle |
getBounds()
Returns the bounding box of this polygon. |
Rectangle2D |
getBounds2D()
Returns a high-precision bounding box of this polygon. |
PathIterator |
getPathIterator(AffineTransform transform)
Return an iterator along the shape boundary. |
PathIterator |
getPathIterator(AffineTransform transform,
double flatness)
Return an iterator along the flattened version of the shape boundary. |
boolean |
inside(int x,
int y)
Deprecated. use contains(int, int) instead |
boolean |
intersects(double x,
double y,
double w,
double h)
Test if a high-precision rectangle intersects the shape. |
boolean |
intersects(Rectangle2D r)
Test if a high-precision rectangle intersects the shape. |
void |
invalidate()
Invalidate or flush all cached data. |
void |
reset()
Reset the polygon to be empty. |
void |
translate(int dx,
int dy)
Translates the polygon by adding the specified values to all X and Y coordinates. |
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
addPoint(int, int)
public int[] ypoints
addPoint(int, int)
protected Rectangle bounds
getBounds()
Constructor Detail |
---|
public Polygon()
public Polygon(int[] xpoints, int[] ypoints, int npoints)
xpoints
- the array of X coordinates for this polygonypoints
- the array of Y coordinates for this polygonnpoints
- the total number of endpoints in this polygon
NegativeArraySizeException
- if npoints is negative
IndexOutOfBoundsException
- if npoints exceeds either array
NullPointerException
- if xpoints or ypoints is nullMethod Detail |
---|
public void reset()
invalidate()
public void invalidate()
contains
.
getBounds()
public void translate(int dx, int dy)
dx
- the amount to add to all X coordinatesdy
- the amount to add to all Y coordinatespublic void addPoint(int x, int y)
x
- the X coordinate of the point to addy
- the Y coordiante of the point to addpublic Rectangle getBounds()
getBounds
in interface Shape
getBounds2D()
public Rectangle getBoundingBox()
getBounds()
instead
getBounds2D()
public boolean contains(Point p)
p
- the point to test
NullPointerException
- if p is nullcontains(double, double)
public boolean contains(int x, int y)
x
- the X coordinate of the point to testy
- the Y coordinate of the point to test
contains(double, double)
public boolean inside(int x, int y)
contains(int, int)
instead
x
- the X coordinate of the point to testy
- the Y coordinate of the point to test
contains(double, double)
public Rectangle2D getBounds2D()
getBounds2D
in interface Shape
getBounds()
public boolean contains(double x, double y)
contains
in interface Shape
x
- the X coordinate of the point to testy
- the Y coordinate of the point to test
public boolean contains(Point2D p)
contains
in interface Shape
p
- the point to test
NullPointerException
- if p is nullcontains(double, double)
public boolean intersects(double x, double y, double w, double h)
intersects
in interface Shape
x
- the x coordinate of the rectangley
- the y coordinate of the rectanglew
- the width of the rectangle, treated as point if negativeh
- the height of the rectangle, treated as point if negative
Area
public boolean intersects(Rectangle2D r)
intersects
in interface Shape
r
- the rectangle
NullPointerException
- if r is nullintersects(double, double, double, double)
public boolean contains(double x, double y, double w, double h)
contains
in interface Shape
x
- the x coordinate of the rectangley
- the y coordinate of the rectanglew
- the width of the rectangle, treated as point if negativeh
- the height of the rectangle, treated as point if negative
Area
public boolean contains(Rectangle2D r)
contains
in interface Shape
r
- the rectangle
NullPointerException
- if r is nullcontains(double, double, double, double)
public PathIterator getPathIterator(AffineTransform transform)
getPathIterator
in interface Shape
transform
- an optional transform to apply to the iterator
public PathIterator getPathIterator(AffineTransform transform, double flatness)
getPathIterator
in interface Shape
transform
- an optional transform to apply to the iteratorflatness
- the maximum distance for deviation from the real boundary
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |