Package org.apache.batik.ext.awt.geom
Class Polygon2D
- java.lang.Object
-
- org.apache.batik.ext.awt.geom.Polygon2D
-
- All Implemented Interfaces:
java.awt.Shape,java.io.Serializable,java.lang.Cloneable
public class Polygon2D extends java.lang.Object implements java.awt.Shape, java.lang.Cloneable, java.io.SerializableThis class is a Polygon with float coordinates.- Version:
- $Id: Polygon2D.java 1831630 2018-05-15 12:56:55Z ssteiner $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.awt.geom.Rectangle2DboundsBounds of the Polygon2D.private java.awt.geom.GeneralPathclosedPathintnpointsThe total number of points.private java.awt.geom.GeneralPathpathfloat[]xpointsThe array of x coordinates.float[]ypointsThe array of x coordinates.
-
Constructor Summary
Constructors Constructor Description Polygon2D()Creates 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(java.awt.geom.Rectangle2D rec)Constructs and initializes aPolygon2Dfrom the specified Rectangle2D.Polygon2D(java.awt.Polygon pol)Constructs and initializes aPolygon2Dfrom the specified Polygon.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPoint(float x, float y)Appends the specified coordinates to thisPolygon2D.voidaddPoint(java.awt.geom.Point2D p)private voidcalculatePath()java.lang.Objectclone()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.booleancontains(java.awt.geom.Point2D p)Tests if a specifiedPoint2Dis inside the boundary of thisPolygon.booleancontains(java.awt.geom.Rectangle2D r)Tests if the interior of thisPolygonentirely contains the specifiedRectangle2D.booleancontains(java.awt.Point p)Determines whether the specifiedPointis inside thisPolygon.java.awt.RectanglegetBounds()java.awt.geom.Rectangle2DgetBounds2D()Returns the high precision bounding box of theShape.java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.AffineTransform at)Returns an iterator object that iterates along the boundary of thisPolygonand provides access to the geometry of the outline of thisPolygon.java.awt.geom.PathIteratorgetPathIterator(java.awt.geom.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.java.awt.PolygongetPolygon()Polyline2DgetPolyline2D()booleanintersects(double x, double y, double w, double h)Tests if the interior of thisPolygonintersects the interior of a specified set of rectangular coordinates.booleanintersects(java.awt.geom.Rectangle2D r)Tests if the interior of thisPolygonintersects the interior of a specifiedRectangle2D.voidreset()Resets thisPolygonobject to an empty polygon.private voidupdateComputingPath()private voidupdatePath(float x, float y)
-
-
-
Field Detail
-
npoints
public int npoints
The total number of points. The value ofnpointsrepresents the number of valid points in thisPolygon.
-
xpoints
public float[] xpoints
The array of x coordinates. The value ofnpointsis equal to the number of points in thisPolygon2D.
-
ypoints
public float[] ypoints
The array of x coordinates. The value ofnpointsis equal to the number of points in thisPolygon2D.
-
bounds
protected java.awt.geom.Rectangle2D bounds
Bounds of the Polygon2D.- See Also:
getBounds()
-
path
private java.awt.geom.GeneralPath path
-
closedPath
private java.awt.geom.GeneralPath closedPath
-
-
Constructor Detail
-
Polygon2D
public Polygon2D()
Creates an empty Polygon2D.
-
Polygon2D
public Polygon2D(java.awt.geom.Rectangle2D rec)
Constructs and initializes aPolygon2Dfrom the specified Rectangle2D.- Parameters:
rec- the Rectangle2D- Throws:
java.lang.NullPointerException- rec isnull.
-
Polygon2D
public Polygon2D(java.awt.Polygon pol)
Constructs and initializes aPolygon2Dfrom the specified Polygon.- Parameters:
pol- the Polygon- Throws:
java.lang.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:
java.lang.NegativeArraySizeException- if the value ofnpointsis negative.java.lang.IndexOutOfBoundsException- ifnpointsis greater than the length ofxpointsor the length ofypoints.java.lang.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:
java.lang.NegativeArraySizeException- if the value ofnpointsis negative.java.lang.IndexOutOfBoundsException- ifnpointsis greater than the length ofxpointsor the length ofypoints.java.lang.NullPointerException- ifxpointsorypointsisnull.
-
-
Method Detail
-
reset
public void reset()
Resets thisPolygonobject to an empty polygon.
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
calculatePath
private void calculatePath()
-
updatePath
private void updatePath(float x, float y)
-
getPolyline2D
public Polyline2D getPolyline2D()
-
getPolygon
public java.awt.Polygon getPolygon()
-
addPoint
public void addPoint(java.awt.geom.Point2D p)
-
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
public boolean contains(java.awt.Point p)
Determines whether the specifiedPointis inside thisPolygon.- Parameters:
p- the specifiedPointto be tested- Returns:
trueif thePolygoncontains thePoint;falseotherwise.- See Also:
contains(double, double)
-
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
public java.awt.geom.Rectangle2D getBounds2D()
Returns the high precision bounding box of theShape.- Specified by:
getBounds2Din interfacejava.awt.Shape- Returns:
- a
Rectangle2Dthat precisely bounds theShape.
-
getBounds
public java.awt.Rectangle getBounds()
- Specified by:
getBoundsin interfacejava.awt.Shape
-
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.- Specified by:
containsin interfacejava.awt.Shape- Parameters:
x- the specified x coordinatey- the specified y coordinate- Returns:
trueif thePolygoncontains the specified coordinates;falseotherwise.
-
updateComputingPath
private void updateComputingPath()
-
contains
public boolean contains(java.awt.geom.Point2D p)
Tests if a specifiedPoint2Dis inside the boundary of thisPolygon.- Specified by:
containsin interfacejava.awt.Shape- Parameters:
p- a specifiedPoint2D- Returns:
trueif thisPolygoncontains the specifiedPoint2D;falseotherwise.- See Also:
contains(double, double)
-
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 interfacejava.awt.Shape- 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
public boolean intersects(java.awt.geom.Rectangle2D r)
Tests if the interior of thisPolygonintersects the interior of a specifiedRectangle2D.- Specified by:
intersectsin interfacejava.awt.Shape- 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 interfacejava.awt.Shape- 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
public boolean contains(java.awt.geom.Rectangle2D r)
Tests if the interior of thisPolygonentirely contains the specifiedRectangle2D.- Specified by:
containsin interfacejava.awt.Shape- Parameters:
r- the specifiedRectangle2D- Returns:
trueif thisPolygonentirely contains the specifiedRectangle2D;falseotherwise.- See Also:
contains(double, double, double, double)
-
getPathIterator
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
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 interfacejava.awt.Shape- 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
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.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. 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 interfacejava.awt.Shape- 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.
-
-