Package org.apache.batik.ext.awt.geom
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: Polygon2D.java 1831630 2018-05-15 12:56:55Z ssteiner $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Rectangle2D
Bounds of the Polygon2D.private GeneralPath
int
The total number of points.private GeneralPath
float[]
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 aPolygon2D
from the specified parameters.Polygon2D
(int[] xpoints, int[] ypoints, int npoints) Constructs and initializes aPolygon2D
from the specified parameters.Polygon2D
(Rectangle2D rec) Constructs and initializes aPolygon2D
from the specified Rectangle2D.Constructs and initializes aPolygon2D
from the specified Polygon. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPoint
(float x, float y) Appends the specified coordinates to thisPolygon2D
.void
private void
clone()
boolean
contains
(double x, double y) Determines if the specified coordinates are inside thisPolygon
.boolean
contains
(double x, double y, double w, double h) Tests if the interior of thisPolygon
entirely contains the specified set of rectangular coordinates.boolean
contains
(int x, int y) Determines whether the specified coordinates are inside thisPolygon
.boolean
Tests if a specifiedPoint2D
is inside the boundary of thisPolygon
.boolean
Tests if the interior of thisPolygon
entirely contains the specifiedRectangle2D
.boolean
Determines whether the specifiedPoint
is inside thisPolygon
.Returns the high precision bounding box of theShape
.Returns an iterator object that iterates along the boundary of thisPolygon
and 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 thePolygon2D
and provides access to the geometry of the outline of theShape
.boolean
intersects
(double x, double y, double w, double h) Tests if the interior of thisPolygon
intersects the interior of a specified set of rectangular coordinates.boolean
Tests if the interior of thisPolygon
intersects the interior of a specifiedRectangle2D
.void
reset()
Resets thisPolygon
object to an empty polygon.private void
private void
updatePath
(float x, float y)
-
Field Details
-
npoints
public int npointsThe total number of points. The value ofnpoints
represents the number of valid points in thisPolygon
. -
xpoints
public float[] xpointsThe array of x coordinates. The value ofnpoints
is equal to the number of points in thisPolygon2D
. -
ypoints
public float[] ypointsThe array of x coordinates. The value ofnpoints
is equal to the number of points in thisPolygon2D
. -
bounds
Bounds of the Polygon2D.- See Also:
-
path
-
closedPath
-
-
Constructor Details
-
Polygon2D
public Polygon2D()Creates an empty Polygon2D. -
Polygon2D
Constructs and initializes aPolygon2D
from the specified Rectangle2D.- Parameters:
rec
- the Rectangle2D- Throws:
NullPointerException
- rec isnull
.
-
Polygon2D
Constructs and initializes aPolygon2D
from the specified Polygon.- Parameters:
pol
- the Polygon- Throws:
NullPointerException
- pol isnull
.
-
Polygon2D
public Polygon2D(float[] xpoints, float[] ypoints, int npoints) Constructs and initializes aPolygon2D
from 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 ofnpoints
is negative.IndexOutOfBoundsException
- ifnpoints
is greater than the length ofxpoints
or the length ofypoints
.NullPointerException
- ifxpoints
orypoints
isnull
.
-
Polygon2D
public Polygon2D(int[] xpoints, int[] ypoints, int npoints) Constructs and initializes aPolygon2D
from 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 ofnpoints
is negative.IndexOutOfBoundsException
- ifnpoints
is greater than the length ofxpoints
or the length ofypoints
.NullPointerException
- ifxpoints
orypoints
isnull
.
-
-
Method Details
-
reset
public void reset()Resets thisPolygon
object 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
Determines whether the specifiedPoint
is inside thisPolygon
.- Parameters:
p
- the specifiedPoint
to be tested- Returns:
true
if thePolygon
contains thePoint
;false
otherwise.- See Also:
-
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:
true
if thisPolygon
contains the specified coordinates, (x, y);false
otherwise.
-
getBounds2D
Returns the high precision bounding box of theShape
.- Specified by:
getBounds2D
in interfaceShape
- Returns:
- a
Rectangle2D
that 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
Tests if a specifiedPoint2D
is inside the boundary of thisPolygon
. -
intersects
public boolean intersects(double x, double y, double w, double h) Tests if the interior of thisPolygon
intersects the interior of a specified set of rectangular coordinates.- Specified by:
intersects
in 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:
true
if the interior of thisPolygon
and the interior of the specified set of rectangular coordinates intersect each other;false
otherwise.
-
intersects
Tests if the interior of thisPolygon
intersects the interior of a specifiedRectangle2D
.- Specified by:
intersects
in interfaceShape
- Parameters:
r
- a specifiedRectangle2D
- Returns:
true
if thisPolygon
and the interior of the specifiedRectangle2D
intersect each other;false
otherwise.
-
contains
public boolean contains(double x, double y, double w, double h) Tests if the interior of thisPolygon
entirely contains the specified set of rectangular coordinates.- Specified by:
contains
in 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:
true
if thisPolygon
entirely contains the specified set of rectangular coordinates;false
otherwise.
-
contains
Tests if the interior of thisPolygon
entirely contains the specifiedRectangle2D
. -
getPathIterator
Returns an iterator object that iterates along the boundary of thisPolygon
and provides access to the geometry of the outline of thisPolygon
. An optionalAffineTransform
can be specified so that the coordinates returned in the iteration are transformed accordingly.- Specified by:
getPathIterator
in interfaceShape
- Parameters:
at
- an optionalAffineTransform
to be applied to the coordinates as they are returned in the iteration, ornull
if untransformed coordinates are desired- Returns:
- a
PathIterator
object that provides access to the geometry of thisPolygon
.
-
getPathIterator
Returns an iterator object that iterates along the boundary of thePolygon2D
and 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, theflatness
parameter is ignored.- Specified by:
getPathIterator
in interfaceShape
- Parameters:
at
- an optionalAffineTransform
to be applied to the coordinates as they are returned in the iteration, ornull
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 theflatness
parameter is ignored.- Returns:
- a
PathIterator
object that provides access to theShape
object's geometry.
-