public class Polyline2D extends java.lang.Object implements java.awt.Shape, java.lang.Cloneable
Polygon2D, except that
the figure is not closed.| Modifier and Type | Field and Description |
|---|---|
int |
npoints
The total number of points.
|
double[] |
xpoints
The array of x coordinates.
|
double[] |
ypoints
The array of y coordinates.
|
| Constructor and Description |
|---|
Polyline2D()
Creates an empty Polyline2D.
|
Polyline2D(double[] xpoints,
double[] ypoints,
int npoints)
Constructs and initializes a
Polyline2D from the specified
parameters. |
Polyline2D(int[] xpoints,
int[] ypoints,
int npoints)
Constructs and initializes a
Polyline2D from the specified
parameters. |
Polyline2D(java.awt.geom.Line2D line) |
| Modifier and Type | Method and Description |
|---|---|
void |
addPoint(double x,
double y)
Appends the specified coordinates to this
Polyline2D. |
void |
addPoint(java.awt.geom.Point2D p) |
void |
calculatePath() |
java.lang.Object |
clone() |
boolean |
contains(double x,
double y)
Determines if the specified coordinates are inside this
Polyline2D. |
boolean |
contains(double x,
double y,
double w,
double h)
Tests if the interior of this
Polyline2D entirely
contains the specified set of rectangular coordinates. |
boolean |
contains(int x,
int y)
Determines whether the specified coordinates are inside this
Polyline2D. |
boolean |
contains(java.awt.Point p)
Determines whether the specified
Point is inside this Polyline2D. |
boolean |
contains(java.awt.geom.Point2D p)
Tests if a specified
Point2D is inside the boundary of this Polyline2D. |
boolean |
contains(java.awt.geom.Rectangle2D r)
Tests if the interior of this
Polyline2D entirely
contains the specified Rectangle2D. |
java.awt.Rectangle |
getBounds()
Gets the bounding box of this
Polyline2D. |
java.awt.geom.Rectangle2D |
getBounds2D()
Returns the high precision bounding box of the
Shape. |
java.awt.geom.PathIterator |
getPathIterator(java.awt.geom.AffineTransform at)
Returns an iterator object that iterates along the boundary of this
Polygon and provides access to
the geometry
of the outline of this Polygon. |
java.awt.geom.PathIterator |
getPathIterator(java.awt.geom.AffineTransform at,
double flatness)
Returns an iterator object that iterates along the boundary of
the
Shape and provides access to the geometry of the
outline of the Shape. |
Polygon2D |
getPolygon2D() |
boolean |
intersects(double x,
double y,
double w,
double h)
Tests if the interior of this
Polygon intersects the
interior of a specified set of rectangular coordinates. |
boolean |
intersects(java.awt.geom.Rectangle2D r)
Tests if the interior of this
Polygon intersects the
interior of a specified Rectangle2D. |
void |
reset()
Resets this
Polyline2D object to an empty polygon. |
public int npoints
npoints represents the number of points in this
Polyline2D.public double[] xpoints
npoints is equal to the
number of points in this Polyline2D.public Polyline2D()
public Polyline2D(double[] xpoints, double[] ypoints, int npoints)
Polyline2D from the specified
parameters.xpoints - an array of x coordinatesypoints - an array of y coordinatesnpoints - the total number of points in the Polyline2Djava.lang.NegativeArraySizeException - if the value of npoints is negative.java.lang.IndexOutOfBoundsException - if npoints is
greater than the length of xpoints or the length of ypoints.java.lang.NullPointerException - if xpoints or ypoints is null.public Polyline2D(int[] xpoints, int[] ypoints, int npoints)
Polyline2D from the specified
parameters.xpoints - an array of x coordinatesypoints - an array of y coordinatesnpoints - the total number of points in the Polyline2Djava.lang.NegativeArraySizeException - if the value of npoints is negative.java.lang.IndexOutOfBoundsException - if npoints is
greater than the length of xpoints or the length of ypoints.java.lang.NullPointerException - if xpoints or ypoints is null.public Polyline2D(java.awt.geom.Line2D line)
public void reset()
Polyline2D 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 empty Polyline2D 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.public java.lang.Object clone()
clone in class java.lang.Objectpublic void calculatePath()
public void addPoint(java.awt.geom.Point2D p)
public void addPoint(double x, double y)
Polyline2D.
If an operation that calculates the bounding box of this Polyline2D has already been performed, such
as getBounds or contains, then this method updates the bounding box.
x - the specified x coordinatey - the specified y coordinatePolygon.getBounds(),
Polygon.contains(double,double)public java.awt.geom.Rectangle2D getBounds2D()
Shape.getBounds2D in interface java.awt.ShapeRectangle2D that precisely
bounds the Shape.public java.awt.Rectangle getBounds()
Polyline2D.
The bounding box is the smallest Rectangle whose
sides are parallel to the x and y axes of the
coordinate space, and can completely contain the Polyline2D.getBounds in interface java.awt.ShapeRectangle that defines the bounds of this Polyline2D.public boolean contains(java.awt.Point p)
Point is inside this Polyline2D.
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.public boolean contains(double x, double y)
Polyline2D.
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 in interface java.awt.Shapepublic boolean contains(int x, int y)
Polyline2D.
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.public boolean contains(java.awt.geom.Point2D p)
Point2D is inside the boundary of this Polyline2D.
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 in interface java.awt.Shapepublic boolean intersects(double x, double y, double w, double h)
Polygon intersects the
interior of a specified set of rectangular coordinates.intersects in interface java.awt.Shapex - 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 shapetrue if the interior of this Polygon and the interior of the
specified set of rectangular
coordinates intersect each other; false otherwise.public boolean intersects(java.awt.geom.Rectangle2D r)
Polygon intersects the
interior of a specified Rectangle2D.intersects in interface java.awt.Shaper - a specified Rectangle2Dtrue if this Polygon and the
interior of the specified Rectangle2D intersect each other; false otherwise.public boolean contains(double x, double y, double w, double h)
Polyline2D 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 in interface java.awt.Shapepublic boolean contains(java.awt.geom.Rectangle2D r)
Polyline2D entirely
contains the specified Rectangle2D.
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 in interface java.awt.Shapepublic Polygon2D getPolygon2D()
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at)
Polygon and provides access to
the geometry
of the outline of this Polygon. An optional AffineTransform can be specified so that the
coordinates
returned in the iteration are transformed accordingly.getPathIterator in interface java.awt.Shapeat - an optional AffineTransform to be applied to the
coordinates as they are returned in the iteration, or null if untransformed coordinates are
desiredPathIterator object that provides access to the
geometry of this Polygon.public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)
Shape and provides access to the geometry of the
outline of the Shape. Only SEG_MOVETO and SEG_LINETO, point types
are returned by the iterator.
Since polylines are already flat, the flatness parameter
is ignored.getPathIterator in interface java.awt.Shapeat - an optional AffineTransform to be applied to the
coordinates as they are returned in the iteration, or null 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 the flatness parameter is ignored.PathIterator object that provides access to the Shape object's geometry.