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.Serializable
This 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.Rectangle2D
bounds
Bounds of the Polygon2D.private java.awt.geom.GeneralPath
closedPath
int
npoints
The total number of points.private java.awt.geom.GeneralPath
path
float[]
xpoints
The array of x coordinates.float[]
ypoints
The array of x coordinates.
-
Constructor Summary
Constructors Constructor Description Polygon2D()
Creates 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(java.awt.geom.Rectangle2D rec)
Constructs and initializes aPolygon2D
from the specified Rectangle2D.Polygon2D(java.awt.Polygon pol)
Constructs and initializes aPolygon2D
from the specified Polygon.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPoint(float x, float y)
Appends the specified coordinates to thisPolygon2D
.void
addPoint(java.awt.geom.Point2D p)
private void
calculatePath()
java.lang.Object
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
contains(java.awt.geom.Point2D p)
Tests if a specifiedPoint2D
is inside the boundary of thisPolygon
.boolean
contains(java.awt.geom.Rectangle2D r)
Tests if the interior of thisPolygon
entirely contains the specifiedRectangle2D
.boolean
contains(java.awt.Point p)
Determines whether the specifiedPoint
is inside thisPolygon
.java.awt.Rectangle
getBounds()
java.awt.geom.Rectangle2D
getBounds2D()
Returns the high precision bounding box of theShape
.java.awt.geom.PathIterator
getPathIterator(java.awt.geom.AffineTransform at)
Returns an iterator object that iterates along the boundary of thisPolygon
and provides access to the geometry of the outline of thisPolygon
.java.awt.geom.PathIterator
getPathIterator(java.awt.geom.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
.java.awt.Polygon
getPolygon()
Polyline2D
getPolyline2D()
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
intersects(java.awt.geom.Rectangle2D r)
Tests if the interior of thisPolygon
intersects the interior of a specifiedRectangle2D
.void
reset()
Resets thisPolygon
object to an empty polygon.private void
updateComputingPath()
private void
updatePath(float x, float y)
-
-
-
Field Detail
-
npoints
public int npoints
The total number of points. The value ofnpoints
represents the number of valid points in thisPolygon
.
-
xpoints
public float[] xpoints
The array of x coordinates. The value ofnpoints
is equal to the number of points in thisPolygon2D
.
-
ypoints
public float[] ypoints
The array of x coordinates. The value ofnpoints
is 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 aPolygon2D
from the specified Rectangle2D.- Parameters:
rec
- the Rectangle2D- Throws:
java.lang.NullPointerException
- rec isnull
.
-
Polygon2D
public Polygon2D(java.awt.Polygon pol)
Constructs and initializes aPolygon2D
from 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 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:
java.lang.NegativeArraySizeException
- if the value ofnpoints
is negative.java.lang.IndexOutOfBoundsException
- ifnpoints
is greater than the length ofxpoints
or the length ofypoints
.java.lang.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:
java.lang.NegativeArraySizeException
- if the value ofnpoints
is negative.java.lang.IndexOutOfBoundsException
- ifnpoints
is greater than the length ofxpoints
or the length ofypoints
.java.lang.NullPointerException
- ifxpoints
orypoints
isnull
.
-
-
Method Detail
-
reset
public void reset()
Resets thisPolygon
object to an empty polygon.
-
clone
public java.lang.Object clone()
- Overrides:
clone
in 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 specifiedPoint
is inside thisPolygon
.- Parameters:
p
- the specifiedPoint
to be tested- Returns:
true
if thePolygon
contains thePoint
;false
otherwise.- 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:
true
if thisPolygon
contains the specified coordinates, (x, y);false
otherwise.
-
getBounds2D
public java.awt.geom.Rectangle2D getBounds2D()
Returns the high precision bounding box of theShape
.- Specified by:
getBounds2D
in interfacejava.awt.Shape
- Returns:
- a
Rectangle2D
that precisely bounds theShape
.
-
getBounds
public java.awt.Rectangle getBounds()
- Specified by:
getBounds
in 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:
contains
in interfacejava.awt.Shape
- Parameters:
x
- the specified x coordinatey
- the specified y coordinate- Returns:
true
if thePolygon
contains the specified coordinates;false
otherwise.
-
updateComputingPath
private void updateComputingPath()
-
contains
public boolean contains(java.awt.geom.Point2D p)
Tests if a specifiedPoint2D
is inside the boundary of thisPolygon
.- Specified by:
contains
in interfacejava.awt.Shape
- Parameters:
p
- a specifiedPoint2D
- Returns:
true
if thisPolygon
contains the specifiedPoint2D
;false
otherwise.- See Also:
contains(double, double)
-
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 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:
true
if the interior of thisPolygon
and the interior of the specified set of rectangular coordinates intersect each other;false
otherwise.
-
intersects
public boolean intersects(java.awt.geom.Rectangle2D r)
Tests if the interior of thisPolygon
intersects the interior of a specifiedRectangle2D
.- Specified by:
intersects
in interfacejava.awt.Shape
- 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 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:
true
if thisPolygon
entirely contains the specified set of rectangular coordinates;false
otherwise.
-
contains
public boolean contains(java.awt.geom.Rectangle2D r)
Tests if the interior of thisPolygon
entirely contains the specifiedRectangle2D
.- Specified by:
contains
in interfacejava.awt.Shape
- Parameters:
r
- the specifiedRectangle2D
- Returns:
true
if thisPolygon
entirely contains the specifiedRectangle2D
;false
otherwise.- 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 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 interfacejava.awt.Shape
- 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
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.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
. 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 interfacejava.awt.Shape
- 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.
-
-