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
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| protected Rectangle | bounds
The bounds of this |
| private static final int | |
| public int | npoints
The total number of points. |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.1 for interoperability. |
| public int[] | xpoints
The array of X coordinates. |
| public int[] | ypoints
The array of Y coordinates. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | Polygon(int[]
an array of X coordinates xpoints, int[] an array of Y coordinates ypoints, int the total number of points in the
npoints)PolygonConstructs and initializes a |
| Modifier and Type | Method and Description |
|---|---|
| public void | addPoint(int
the specified X coordinate x, int the specified Y coordinate y)Appends the specified coordinates to this |
| pack-priv void | |
| public boolean | |
| public boolean | Returns: true if this Polygon contains
the specified coordinates (x,y);
false otherwise.the specified X coordinate to be tested x, int the specified Y coordinate to be tested y)Determines whether the specified coordinates are inside this
|
| public boolean | contains(double x, double y)
Implements java. Tests if the specified coordinates are inside the boundary of the
|
| public boolean | contains(Point2D p)
Implements java. Tests if a specified |
| public boolean | contains(double x, double y, double w, double h)
Implements java. Tests if the interior of the |
| public boolean | contains(Rectangle2D r)
Implements java. Tests if the interior of the |
| public Rectangle | Returns: the bounds of thisPolygon.
Deprecated
As of JDK version 1.1,
replaced by
getBounds().
Returns the bounds of this |
| public Rectangle | Returns: aRectangle that defines the bounds of this
Polygon.Implements java. Gets the bounding box of this |
| public Rectangle2D | getBounds2D()
Implements java. Returns a high precision and more accurate bounding box of
the |
| private Crossings | |
| public PathIterator | getPathIterator(AffineTransform
an optional at)AffineTransform to be applied to the
coordinates as they are returned in the iteration, or
null if untransformed coordinates are desiredImplements java. Returns an iterator object that iterates along the boundary of this
|
| public PathIterator | Returns: aPathIterator object that provides access to the
Shape object's geometry.an optional at, double AffineTransform to be applied to the
coordinates as they are returned in the iteration, or
null if untransformed coordinates are desiredthe maximum amount that the control points
for a given curve can vary from collinear before a subdivided
curve is replaced by a straight line connecting the
endpoints. Since polygons are already flat the
flatness)flatness parameter is ignored.Implements java. Returns an iterator object that iterates along the boundary of
the |
| public boolean | Returns: true if this Polygon contains
the specified coordinates (x,y);
false otherwise.the specified X coordinate to be tested x, int the specified Y coordinate to be tested y)
Deprecated
As of JDK version 1.1,
replaced by
contains(int, int).
Determines whether the specified coordinates are contained in this
|
| public boolean | intersects(double x, double y, double w, double h)
Implements java. Tests if the interior of the |
| public boolean | intersects(Rectangle2D r)
Implements java. Tests if the interior of the |
| public void | invalidate()
Invalidates or flushes any internally-cached data that depends
on the vertex coordinates of this |
| public void | |
| public void | translate(int
the amount to translate along the X axis deltaX, int the amount to translate along the Y axis deltaY)Translates the vertices of the |
| pack-priv void |
| bounds | back to summary |
|---|---|
| protected Rectangle bounds The bounds of this
| |
| MIN_LENGTH | back to summary |
|---|---|
| private static final int MIN_LENGTH | |
| npoints | back to summary |
|---|---|
| public int npoints The total number of points. The value of
| |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Use serialVersionUID from JDK 1.1 for interoperability. | |
| xpoints | back to summary |
|---|---|
| public int[] xpoints The array of X coordinates. The number of elements in
this array might be more than the number of X coordinates
in this
| |
| ypoints | back to summary |
|---|---|
| public int[] ypoints The array of Y coordinates. The number of elements in
this array might be more than the number of Y coordinates
in this
| |
| Polygon | back to summary |
|---|---|
| public Polygon() Creates an empty polygon.
| |
| Polygon | back to summary |
|---|---|
| public Polygon(int[] xpoints, int[] ypoints, int npoints) Constructs and initializes a
| |
| addPoint | back to summary |
|---|---|
| public void addPoint(int x, int y) Appends the specified coordinates to this
If an operation that calculates the bounding box of this
| |
| calculateBounds | back to summary |
|---|---|
| pack-priv void calculateBounds(int[] xpoints, int[] ypoints, int npoints) | |
| contains | back to summary |
|---|---|
| public boolean contains(Point p) Determines whether the specified
| |
| contains | back to summary |
|---|---|
| public boolean contains(int x, int y) Determines whether the specified coordinates are inside this
| |
| contains | back to summary |
|---|---|
| public boolean contains(double x, double y) Implements java. Doc from java. Tests if the specified coordinates are inside the boundary of the
| |
| contains | back to summary |
|---|---|
| public boolean contains(Point2D p) Implements java. Doc from java. Tests if a specified
| |
| contains | back to summary |
|---|---|
| public boolean contains(double x, double y, double w, double h) Implements java. Doc from java. Tests if the interior of the
The
Shapes this method might
return false even though the Shape contains
the rectangular area.
The Area class performs
more accurate geometric computations than most
Shape objects and therefore can be used if a more precise
answer is required.
| |
| contains | back to summary |
|---|---|
| public boolean contains(Rectangle2D r) Implements java. Doc from java. Tests if the interior of the
Shapes this method might
return false even though the Shape contains
the Rectangle2D.
The Area class performs
more accurate geometric computations than most
Shape objects and therefore can be used if a more precise
answer is required.
| |
| getBoundingBox | back to summary |
|---|---|
| public Rectangle getBoundingBox()
Deprecated As of JDK version 1.1,
replaced by Returns the bounds of this
| |
| getBounds | back to summary |
|---|---|
| public Rectangle getBounds() Implements java. Gets the bounding box of this
| |
| getBounds2D | back to summary |
|---|---|
| public Rectangle2D getBounds2D() Implements java. Doc from java. Returns a high precision and more accurate bounding box of
the
Note that the
definition of insideness can lead to situations where points
on the defining outline of the
If a
If a
| |
| getCrossings | back to summary |
|---|---|
| private Crossings getCrossings(double xlo, double ylo, double xhi, double yhi) | |
| getPathIterator | back to summary |
|---|---|
| public PathIterator getPathIterator(AffineTransform at) Implements java. Returns an iterator object that iterates along the boundary of this
| |
| getPathIterator | back to summary |
|---|---|
| public PathIterator getPathIterator(AffineTransform at, double flatness) Implements java. Returns an iterator object that iterates along the boundary of
the
| |
| inside | back to summary |
|---|---|
| public boolean inside(int x, int y)
Deprecated As of JDK version 1.1,
replaced by Determines whether the specified coordinates are contained in this
| |
| intersects | back to summary |
|---|---|
| public boolean intersects(double x, double y, double w, double h) Implements java. Doc from java. Tests if the interior of the
The
Shapes this method might
return true even though the rectangular area does not
intersect the Shape.
The Area class performs
more accurate computations of geometric intersection than most
Shape objects and therefore can be used if a more precise
answer is required.
| |
| intersects | back to summary |
|---|---|
| public boolean intersects(Rectangle2D r) Implements java. Doc from java. Tests if the interior of the
Shapes this method might
return true even though the Rectangle2D does not
intersect the Shape.
The Area class performs
more accurate computations of geometric intersection than most
Shape objects and therefore can be used if a more precise
answer is required.
| |
| invalidate | back to summary |
|---|---|
| public void invalidate() Invalidates or flushes any internally-cached data that depends
on the vertex coordinates of this
| |
| reset | back to summary |
|---|---|
| public void reset() Resets this
| |
| translate | back to summary |
|---|---|
| public void translate(int deltaX, int deltaY) Translates the vertices of the
| |
| updateBounds | back to summary |
|---|---|
| pack-priv void updateBounds(int x, int y) | |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | |
| pack-priv Polygon | |
| pack-priv AffineTransform |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public int | Returns: an integer representing the type and coordinates of the current path segment.a coords)float array that specifies the
coordinates of the point(s)Implements java. Returns the coordinates and type of the current path segment in the iteration. |
| public int | Returns: an integer representing the type and coordinates of the current path segment.a coords)double array that specifies the
coordinates of the point(s)Implements java. Returns the coordinates and type of the current path segment in the iteration. |
| public int | Returns: an integer representing the current winding rule.Implements java. Returns the winding rule for determining the interior of the path. |
| public boolean | Returns: true if there are more points to read;
false otherwise.Implements java. Tests if there are more points to read. |
| public void | next()
Implements java. Moves the iterator forwards, along the primary direction of traversal, to the next segment of the path when there are more points in that direction. |
| index | back to summary |
|---|---|
| pack-priv int index | |
| poly | back to summary |
|---|---|
| pack-priv Polygon poly | |
| transform | back to summary |
|---|---|
| pack-priv AffineTransform transform | |
| PolygonPathIterator | back to summary |
|---|---|
| public PolygonPathIterator(Polygon pg, AffineTransform at) | |
| currentSegment | back to summary |
|---|---|
| public int currentSegment(float[] coords) Implements java. Returns the coordinates and type of the current path segment in
the iteration.
The return value is the path segment type:
SEG_MOVETO, SEG_LINETO, or SEG_CLOSE.
A
| |
| currentSegment | back to summary |
|---|---|
| public int currentSegment(double[] coords) Implements java. Returns the coordinates and type of the current path segment in
the iteration.
The return value is the path segment type:
SEG_MOVETO, SEG_LINETO, or SEG_CLOSE.
A
| |
| getWindingRule | back to summary |
|---|---|
| public int getWindingRule() Implements java. Returns the winding rule for determining the interior of the path.
| |
| isDone | back to summary |
|---|---|
| public boolean isDone() Implements java. Tests if there are more points to read.
| |
| next | back to summary |
|---|---|
| public void next() Implements java. Moves the iterator forwards, along the primary direction of traversal, to the next segment of the path when there are more points in that direction. | |