java.lang.Object
io.sf.carte.echosvg.ext.awt.geom.Polyline2D
- All Implemented Interfaces:
Shape
,Serializable
,Cloneable
This class has the same behavior than
Polygon2D
, except that the
figure is not closed.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected Rectangle2D
Bounds of the Polyline2D.int
The total number of points.float[]
The array of x coordinates.float[]
The array of x coordinates. -
Constructor Summary
ConstructorDescriptionCreates an empty Polyline2D.Polyline2D
(float[] xpoints, float[] ypoints, int npoints) Constructs and initializes aPolyline2D
from the specified parameters.Polyline2D
(int[] xpoints, int[] ypoints, int npoints) Constructs and initializes aPolyline2D
from the specified parameters.Polyline2D
(Line2D line) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPoint
(float x, float y) Appends the specified coordinates to thisPolyline2D
.void
clone()
boolean
contains
(double x, double y) Determines if the specified coordinates are inside thisPolyline2D
.boolean
contains
(double x, double y, double w, double h) Tests if the interior of thisPolyline2D
entirely contains the specified set of rectangular coordinates.boolean
contains
(int x, int y) Determines whether the specified coordinates are inside thisPolyline2D
.boolean
Tests if a specifiedPoint2D
is inside the boundary of thisPolyline2D
.boolean
Tests if the interior of thisPolyline2D
entirely contains the specifiedRectangle2D
.boolean
Determines whether the specifiedPoint
is inside thisPolyline2D
.Gets the bounding box of thisPolyline2D
.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 theShape
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 thisPolyline2D
object to an empty polygon.
-
Field Details
-
npoints
public int npointsThe total number of points. The value ofnpoints
represents the number of points in thisPolyline2D
. -
xpoints
public float[] xpointsThe array of x coordinates. The value ofnpoints
is equal to the number of points in thisPolyline2D
. -
ypoints
public float[] ypointsThe array of x coordinates. The value ofnpoints
is equal to the number of points in thisPolyline2D
. -
bounds
Bounds of the Polyline2D.- See Also:
-
-
Constructor Details
-
Polyline2D
public Polyline2D()Creates an empty Polyline2D. -
Polyline2D
public Polyline2D(float[] xpoints, float[] ypoints, int npoints) Constructs and initializes aPolyline2D
from the specified parameters.- Parameters:
xpoints
- an array of x coordinatesypoints
- an array of y coordinatesnpoints
- the total number of points in thePolyline2D
- Throws:
NegativeArraySizeException
- if the value ofnpoints
is negative.IndexOutOfBoundsException
- ifnpoints
is greater than the length ofxpoints
or the length ofypoints
.NullPointerException
- ifxpoints
orypoints
isnull
.
-
Polyline2D
public Polyline2D(int[] xpoints, int[] ypoints, int npoints) Constructs and initializes aPolyline2D
from the specified parameters.- Parameters:
xpoints
- an array of x coordinatesypoints
- an array of y coordinatesnpoints
- the total number of points in thePolyline2D
- Throws:
NegativeArraySizeException
- if the value ofnpoints
is negative.IndexOutOfBoundsException
- ifnpoints
is greater than the length ofxpoints
or the length ofypoints
.NullPointerException
- ifxpoints
orypoints
isnull
.
-
Polyline2D
-
-
Method Details
-
reset
public void reset()Resets thisPolyline2D
object to an empty polygon. The coordinate arrays and the data in them are left untouched but the number of points is reset to zero to mark the old vertex data as invalid and to start accumulating new vertex data at the beginning. All internally-cached data relating to the old vertices are discarded. Note that since the coordinate arrays from before the reset are reused, creating a new emptyPolyline2D
might be more memory efficient than resetting the current one if the number of vertices in the new polyline data is significantly smaller than the number of vertices in the data from before the reset. -
clone
-
addPoint
-
addPoint
public void addPoint(float x, float y) Appends the specified coordinates to thisPolyline2D
.If an operation that calculates the bounding box of this
Polyline2D
has already been performed, such asgetBounds
orcontains
, then this method updates the bounding box.- Parameters:
x
- the specified x coordinatey
- the specified y coordinate- See Also:
-
getBounds
Gets the bounding box of thisPolyline2D
. The bounding box is the smallestRectangle
whose sides are parallel to the x and y axes of the coordinate space, and can completely contain thePolyline2D
. -
contains
Determines whether the specifiedPoint
is inside thisPolyline2D
. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area. -
contains
public boolean contains(double x, double y) Determines if the specified coordinates are inside thisPolyline2D
. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area. -
contains
public boolean contains(int x, int y) Determines whether the specified coordinates are inside thisPolyline2D
. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area. -
getBounds2D
Returns the high precision bounding box of theShape
.- Specified by:
getBounds2D
in interfaceShape
- Returns:
- a
Rectangle2D
that precisely bounds theShape
.
-
contains
Tests if a specifiedPoint2D
is inside the boundary of thisPolyline2D
. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area. -
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 thisPolyline2D
entirely contains the specified set of rectangular coordinates. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area. -
contains
Tests if the interior of thisPolyline2D
entirely contains the specifiedRectangle2D
. This method is required to implement the Shape interface, but in the case of Line2D objects it always returns false since a line contains no area. -
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
.
-
getPolygon2D
-
getPathIterator
Returns an iterator object that iterates along the boundary of theShape
and provides access to the geometry of the outline of theShape
. Only SEG_MOVETO and SEG_LINETO, point types are returned by the iterator. Since polylines 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.
-