Class Polygon2D
java.lang.Object
org.apache.batik.ext.awt.geom.Polygon2D
- All Implemented Interfaces:
Shape, Serializable, Cloneable
This class is a Polygon with float coordinates.
- Version:
- $Id$
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Rectangle2DBounds of the Polygon2D.private GeneralPathintThe total number of points.private GeneralPathfloat[]The array of x coordinates.float[]The array of x coordinates. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty Polygon2D.Polygon2D(float[] xpoints, float[] ypoints, int npoints) Constructs and initializes aPolygon2Dfrom the specified parameters.Polygon2D(int[] xpoints, int[] ypoints, int npoints) Constructs and initializes aPolygon2Dfrom the specified parameters.Polygon2D(Rectangle2D rec) Constructs and initializes aPolygon2Dfrom the specified Rectangle2D.Constructs and initializes aPolygon2Dfrom the specified Polygon. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPoint(float x, float y) Appends the specified coordinates to thisPolygon2D.voidprivate voidclone()booleancontains(double x, double y) Determines if the specified coordinates are inside thisPolygon.booleancontains(double x, double y, double w, double h) Tests if the interior of thisPolygonentirely contains the specified set of rectangular coordinates.booleancontains(int x, int y) Determines whether the specified coordinates are inside thisPolygon.booleanTests if a specifiedPoint2Dis inside the boundary of thisPolygon.booleanTests if the interior of thisPolygonentirely contains the specifiedRectangle2D.booleanDetermines whether the specifiedPointis inside thisPolygon.Returns the high precision bounding box of theShape.Returns an iterator object that iterates along the boundary of thisPolygonand provides access to the geometry of the outline of thisPolygon.getPathIterator(AffineTransform at, double flatness) Returns an iterator object that iterates along the boundary of thePolygon2Dand provides access to the geometry of the outline of theShape.booleanintersects(double x, double y, double w, double h) Tests if the interior of thisPolygonintersects the interior of a specified set of rectangular coordinates.booleanTests if the interior of thisPolygonintersects the interior of a specifiedRectangle2D.voidreset()Resets thisPolygonobject to an empty polygon.private voidprivate voidupdatePath(float x, float y)
-
Field Details
-
npoints
public int npointsThe total number of points. The value ofnpointsrepresents the number of valid points in thisPolygon. -
xpoints
public float[] xpointsThe array of x coordinates. The value ofnpointsis equal to the number of points in thisPolygon2D. -
ypoints
public float[] ypointsThe array of x coordinates. The value ofnpointsis equal to the number of points in thisPolygon2D. -
bounds
-
path
-
closedPath
-
-
Constructor Details
-
Polygon2D
public Polygon2D()Creates an empty Polygon2D. -
Polygon2D
Constructs and initializes aPolygon2Dfrom the specified Rectangle2D.- Parameters:
rec- the Rectangle2D- Throws:
NullPointerException- rec isnull.
-
Polygon2D
Constructs and initializes aPolygon2Dfrom the specified Polygon.- Parameters:
pol- the Polygon- Throws:
NullPointerException- pol isnull.
-
Polygon2D
public Polygon2D(float[] xpoints, float[] ypoints, int npoints) Constructs and initializes aPolygon2Dfrom the specified parameters.- Parameters:
xpoints- an array of x coordinatesypoints- an array of y coordinatesnpoints- the total number of points in thePolygon2D- Throws:
NegativeArraySizeException- if the value ofnpointsis negative.IndexOutOfBoundsException- ifnpointsis greater than the length ofxpointsor the length ofypoints.NullPointerException- ifxpointsorypointsisnull.
-
Polygon2D
public Polygon2D(int[] xpoints, int[] ypoints, int npoints) Constructs and initializes aPolygon2Dfrom the specified parameters.- Parameters:
xpoints- an array of x coordinatesypoints- an array of y coordinatesnpoints- the total number of points in thePolygon2D- Throws:
NegativeArraySizeException- if the value ofnpointsis negative.IndexOutOfBoundsException- ifnpointsis greater than the length ofxpointsor the length ofypoints.NullPointerException- ifxpointsorypointsisnull.
-
-
Method Details
-
reset
public void reset()Resets thisPolygonobject to an empty polygon. -
clone
-
calculatePath
private void calculatePath() -
updatePath
private void updatePath(float x, float y) -
getPolyline2D
-
getPolygon
-
addPoint
-
addPoint
public void addPoint(float x, float y) Appends the specified coordinates to thisPolygon2D.- Parameters:
x- the specified x coordinatey- the specified y coordinate
-
contains
-
contains
public boolean contains(int x, int y) Determines whether the specified coordinates are inside thisPolygon.- Parameters:
x- the specified x coordinate to be testedy- the specified y coordinate to be tested- Returns:
trueif thisPolygoncontains the specified coordinates, (x, y);falseotherwise.
-
getBounds2D
Returns the high precision bounding box of theShape.- Specified by:
getBounds2Din interfaceShape- Returns:
- a
Rectangle2Dthat precisely bounds theShape.
-
getBounds
-
contains
public boolean contains(double x, double y) Determines if the specified coordinates are inside thisPolygon. For the definition of insideness, see the class comments ofShape. -
updateComputingPath
private void updateComputingPath() -
contains
-
intersects
public boolean intersects(double x, double y, double w, double h) Tests if the interior of thisPolygonintersects the interior of a specified set of rectangular coordinates.- Specified by:
intersectsin interfaceShape- Parameters:
x- 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 shape- Returns:
trueif the interior of thisPolygonand the interior of the specified set of rectangular coordinates intersect each other;falseotherwise.
-
intersects
Tests if the interior of thisPolygonintersects the interior of a specifiedRectangle2D.- Specified by:
intersectsin interfaceShape- Parameters:
r- a specifiedRectangle2D- Returns:
trueif thisPolygonand the interior of the specifiedRectangle2Dintersect each other;falseotherwise.
-
contains
public boolean contains(double x, double y, double w, double h) Tests if the interior of thisPolygonentirely contains the specified set of rectangular coordinates.- Specified by:
containsin interfaceShape- Parameters:
x- 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 coordinates- Returns:
trueif thisPolygonentirely contains the specified set of rectangular coordinates;falseotherwise.
-
contains
Tests if the interior of thisPolygonentirely contains the specifiedRectangle2D. -
getPathIterator
Returns an iterator object that iterates along the boundary of thisPolygonand provides access to the geometry of the outline of thisPolygon. An optionalAffineTransformcan be specified so that the coordinates returned in the iteration are transformed accordingly.- Specified by:
getPathIteratorin interfaceShape- Parameters:
at- an optionalAffineTransformto be applied to the coordinates as they are returned in the iteration, ornullif untransformed coordinates are desired- Returns:
- a
PathIteratorobject that provides access to the geometry of thisPolygon.
-
getPathIterator
Returns an iterator object that iterates along the boundary of thePolygon2Dand provides access to the geometry of the outline of theShape. Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by the iterator. Since polygons are already flat, theflatnessparameter is ignored.- Specified by:
getPathIteratorin interfaceShape- Parameters:
at- an optionalAffineTransformto be applied to the coordinates as they are returned in the iteration, ornullif 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 theflatnessparameter is ignored.- Returns:
- a
PathIteratorobject that provides access to theShapeobject's geometry.
-