public class Polygon2D
extends java.lang.Object
implements java.awt.Shape, java.lang.Cloneable, java.io.Serializable
| Modifier and Type | Field and Description |
|---|---|
protected java.awt.geom.Rectangle2D |
bounds
Bounds of the Polygon2D.
|
protected java.awt.geom.GeneralPath |
closedPath |
int |
npoints
The total number of points.
|
protected java.awt.geom.GeneralPath |
path |
float[] |
xpoints
The array of x coordinates.
|
float[] |
ypoints
The array of x coordinates.
|
| Constructor and Description |
|---|
Polygon2D()
Creates an empty Polygon2D.
|
Polygon2D(float[] xpoints,
float[] ypoints,
int npoints)
Constructs and initializes a
Polygon2D from the specified parameters. |
Polygon2D(int[] xpoints,
int[] ypoints,
int npoints)
Constructs and initializes a
Polygon2D from the specified parameters. |
Polygon2D(java.awt.Polygon pol)
Constructs and initializes a
Polygon2D from the specified Polygon. |
Polygon2D(java.awt.geom.Rectangle2D rec)
Constructs and initializes a
Polygon2D from the specified Rectangle2D. |
| Modifier and Type | Method and Description |
|---|---|
void |
addPoint(float x,
float y)
Appends the specified coordinates to this
Polygon2D. |
void |
addPoint(java.awt.geom.Point2D p)
Add a point to this Polygon.
|
protected void |
calculatePath()
Calculate the Polygon associated GeneralPath.
|
java.lang.Object |
clone() |
boolean |
contains(double x,
double y)
Determines if the specified coordinates are inside this
Polygon. |
boolean |
contains(double x,
double y,
double w,
double h)
Tests if the interior of this
Polygon entirely contains the specified set of rectangular coordinates. |
boolean |
contains(int x,
int y)
Determines whether the specified coordinates are inside this
Polygon. |
boolean |
contains(java.awt.Point p)
Determines whether the specified
Point is inside this Polygon. |
boolean |
contains(java.awt.geom.Point2D p)
Tests if a specified
Point2D is inside the boundary of this Polygon. |
boolean |
contains(java.awt.geom.Rectangle2D r)
Tests if the interior of this
Polygon entirely contains the specified Rectangle2D. |
int |
countPoints()
Return the number of points.
|
java.awt.Rectangle |
getBounds()
Returns the bounding box of the
Shape. |
java.awt.geom.Rectangle2D |
getBounds2D()
Returns the high precision bounding box of the
Shape. |
double |
getMaxX()
Return the maximum X coordinate of the Polygon.
|
double |
getMaxY()
Return the maximum Y coordinate of the Polygon.
|
double |
getMinX()
Return the minimum X coordinate of the Polygon.
|
double |
getMinY()
Return the minimum Y coordinate of the Polygon.
|
java.awt.geom.PathIterator |
getPathIterator(java.awt.geom.AffineTransform at)
Returns an iterator object that iterates along the boundary of this
Polygon and provides access to
the geometry of the outline of this Polygon. |
java.awt.geom.PathIterator |
getPathIterator(java.awt.geom.AffineTransform at,
double flatness)
Returns an iterator object that iterates along the boundary of the
Polygon2D and provides access to
the geometry of the outline of the Shape. |
java.util.List<java.awt.geom.Point2D> |
getPoints()
Return the list of points.
|
java.awt.Polygon |
getPolygon()
Retuen the Awt Polygon corresponding with this Polygon2D.
|
Polyline2D |
getPolyline2D()
Return the
Polyline2D corresponding to this Polygon2D. |
float[] |
getXCoordinates()
Return the array of X coordinates of the points.
|
float[] |
getYCoordinates()
Return the array of Y coordinates of the points.
|
boolean |
intersects(double x,
double y,
double w,
double h)
Tests if the interior of this
Polygon intersects the interior of a specified set of rectangular
coordinates. |
boolean |
intersects(java.awt.geom.Rectangle2D r)
Tests if the interior of this
Polygon intersects the interior of a specified Rectangle2D. |
void |
reset()
Resets this
Polygon object to an empty polygon. |
protected void |
updateComputingPath() |
protected void |
updatePath(float x,
float y)
Update the Polygon associated GeneralPath.
|
public int npoints
npoints
represents the number of valid points in this Polygon.public float[] xpoints
npoints is equal to the
number of points in this Polygon2D.public float[] ypoints
npoints is equal to the
number of points in this Polygon2D.protected java.awt.geom.Rectangle2D bounds
getBounds()protected java.awt.geom.GeneralPath path
protected java.awt.geom.GeneralPath closedPath
public Polygon2D()
public Polygon2D(java.awt.geom.Rectangle2D rec)
Polygon2D from the specified Rectangle2D.rec - the Rectangle2Djava.lang.NullPointerException - rec is null.public Polygon2D(java.awt.Polygon pol)
Polygon2D from the specified Polygon.pol - the Polygonjava.lang.NullPointerException - pol is null.public Polygon2D(float[] xpoints,
float[] ypoints,
int npoints)
Polygon2D from the specified parameters.xpoints - an array of x coordinatesypoints - an array of y coordinatesnpoints - the total number of points in the Polygon2Djava.lang.NegativeArraySizeException - if the value of npoints is negative.java.lang.IndexOutOfBoundsException - if npoints is greater than the length of xpoints or the length of ypoints.java.lang.NullPointerException - if xpoints or ypoints is null.public Polygon2D(int[] xpoints,
int[] ypoints,
int npoints)
Polygon2D from the specified parameters.xpoints - an array of x coordinatesypoints - an array of y coordinatesnpoints - the total number of points in the Polygon2Djava.lang.NegativeArraySizeException - if the value of npoints is negative.java.lang.IndexOutOfBoundsException - if npoints is greater than the length of xpoints or the length of ypoints.java.lang.NullPointerException - if xpoints or ypoints is null.public int countPoints()
public float[] getXCoordinates()
public float[] getYCoordinates()
public java.util.List<java.awt.geom.Point2D> getPoints()
public void reset()
Polygon object to an empty polygon.public java.lang.Object clone()
clone in class java.lang.Objectprotected void calculatePath()
protected void updatePath(float x,
float y)
x - the x coordinate of the new Pointy - the y coordinate of the new Pointpublic Polyline2D getPolyline2D()
Polyline2D corresponding to this Polygon2D.public java.awt.Polygon getPolygon()
public void addPoint(java.awt.geom.Point2D p)
p - the pointpublic void addPoint(float x,
float y)
Polygon2D.x - the specified x coordinatey - the specified y coordinatepublic boolean contains(java.awt.Point p)
Point is inside this Polygon.p - the specified Point to be testedtrue if the Polygon contains the
Point; false otherwise.contains(double, double)public boolean contains(int x,
int y)
Polygon.
x - the specified x coordinate to be testedy - the specified y coordinate to be testedtrue if this Polygon contains
the specified coordinates, (x, y);
false otherwise.public double getMinX()
public double getMinY()
public double getMaxX()
public double getMaxY()
public java.awt.geom.Rectangle2D getBounds2D()
Shape.getBounds2D in interface java.awt.ShapeRectangle2D that precisely bounds the Shape.public java.awt.Rectangle getBounds()
Shape.getBounds in interface java.awt.ShapeRectangle that bounds the Shape.public boolean contains(double x,
double y)
Polygon. For the definition of
insideness, see the class comments of Shape.contains in interface java.awt.Shapex - the specified x coordinatey - the specified y coordinatetrue if the Polygon contains the specified coordinates; false otherwise.protected void updateComputingPath()
public boolean contains(java.awt.geom.Point2D p)
Point2D is inside the boundary of this Polygon.contains in interface java.awt.Shapep - a specified Point2Dtrue if this Polygon contains the specified Point2D,
false otherwise.contains(double, double)public boolean intersects(double x,
double y,
double w,
double h)
Polygon intersects the interior of a specified set of rectangular
coordinates.intersects in interface java.awt.Shapex - the x coordinate of the specified rectangular shape's top-left cornery - the y coordinate of the specified rectangular shape's top-left cornerw - the width of the specified rectangular shapeh - the height of the specified rectangular shapetrue if the interior of this Polygon and the interior of the
specified set of rectangular coordinates intersect each other false otherwise.public boolean intersects(java.awt.geom.Rectangle2D r)
Polygon intersects the interior of a specified Rectangle2D.intersects in interface java.awt.Shaper - a specified Rectangle2Dtrue if this Polygon and the interior of the specified Rectangle2D
intersect each other; false otherwise.public boolean contains(double x,
double y,
double w,
double h)
Polygon entirely contains the specified set of rectangular coordinates.contains in interface java.awt.Shapex - the x coordinate of the top-left corner of the
specified set of rectangular coordinatesy - the y coordinate of the top-left corner of the
specified set of rectangular coordinatesw - the width of the set of rectangular coordinatesh - the height of the set of rectangular coordinatestrue if this Polygon entirely
contains the specified set of rectangular
coordinates; false otherwise.public boolean contains(java.awt.geom.Rectangle2D r)
Polygon entirely contains the specified Rectangle2D.contains in interface java.awt.Shaper - the specified Rectangle2Dtrue if this Polygon entirely
contains the specified Rectangle2D;
false otherwise.contains(double, double, double, double)public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
Polygon and provides access to
the geometry of the outline of this Polygon. An optional AffineTransform can be specified so
that the coordinates returned in the iteration are transformed accordingly.getPathIterator in interface java.awt.Shapeat - an optional AffineTransform to be applied to the
coordinates as they are returned in the iteration, or
null if untransformed coordinates are desiredPathIterator object that provides access to the
geometry of this Polygon.public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at,
double flatness)
Polygon2D and provides access to
the geometry of the outline of the Shape. Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types
are returned by the iterator. Since polygons are already flat, the flatness parameter
is ignored.getPathIterator in interface java.awt.Shapeat - an optional AffineTransform to be applied to the coordinates as they are returned in the
iteration, or null if untransformed coordinates are desiredflatness - 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. Since polygons are already flat the
flatness parameter is ignored.PathIterator object that provides access to the Shape object's geometry.Copyright © 2021, 2022, 2025, 2026 Herve Girod. All Rights Reserved. Documentation and source under the BSD 3-Clause licence