Package org.apache.batik.ext.awt.geom
Class Polyline2D
- java.lang.Object
-
- org.apache.batik.ext.awt.geom.Polyline2D
-
- All Implemented Interfaces:
java.awt.Shape,java.io.Serializable,java.lang.Cloneable
public class Polyline2D extends java.lang.Object implements java.awt.Shape, java.lang.Cloneable, java.io.SerializableThis class has the same behavior thanPolygon2D, except that the figure is not closed.- Version:
- $Id: Polyline2D.java 1808001 2017-09-11 09:51:29Z ssteiner $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static floatASSUME_ZEROprotected java.awt.geom.Rectangle2DboundsBounds of the Polyline2D.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 Polyline2D()Creates an empty Polyline2D.Polyline2D(float[] xpoints, float[] ypoints, int npoints)Constructs and initializes aPolyline2Dfrom the specified parameters.Polyline2D(int[] xpoints, int[] ypoints, int npoints)Constructs and initializes aPolyline2Dfrom the specified parameters.Polyline2D(java.awt.geom.Line2D line)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPoint(float x, float y)Appends the specified coordinates to thisPolyline2D.voidaddPoint(java.awt.geom.Point2D p)private voidcalculatePath()java.lang.Objectclone()booleancontains(double x, double y)Determines if the specified coordinates are inside thisPolyline2D.booleancontains(double x, double y, double w, double h)Tests if the interior of thisPolyline2Dentirely contains the specified set of rectangular coordinates.booleancontains(int x, int y)Determines whether the specified coordinates are inside thisPolyline2D.booleancontains(java.awt.geom.Point2D p)Tests if a specifiedPoint2Dis inside the boundary of thisPolyline2D.booleancontains(java.awt.geom.Rectangle2D r)Tests if the interior of thisPolyline2Dentirely contains the specifiedRectangle2D.booleancontains(java.awt.Point p)Determines whether the specifiedPointis inside thisPolyline2D.java.awt.RectanglegetBounds()Gets the bounding box of thisPolyline2D.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 theShapeand provides access to the geometry of the outline of theShape.Polygon2DgetPolygon2D()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 thisPolyline2Dobject to an empty polygon.private voidupdateComputingPath()private voidupdatePath(float x, float y)
-
-
-
Field Detail
-
ASSUME_ZERO
private static final float ASSUME_ZERO
- See Also:
- Constant Field Values
-
npoints
public int npoints
The total number of points. The value ofnpointsrepresents the number of points in thisPolyline2D.
-
xpoints
public float[] xpoints
The array of x coordinates. The value ofnpointsis equal to the number of points in thisPolyline2D.
-
ypoints
public float[] ypoints
The array of x coordinates. The value ofnpointsis equal to the number of points in thisPolyline2D.
-
bounds
protected java.awt.geom.Rectangle2D bounds
Bounds of the Polyline2D.- See Also:
getBounds()
-
path
private java.awt.geom.GeneralPath path
-
closedPath
private java.awt.geom.GeneralPath closedPath
-
-
Constructor Detail
-
Polyline2D
public Polyline2D()
Creates an empty Polyline2D.
-
Polyline2D
public Polyline2D(float[] xpoints, float[] ypoints, int npoints)Constructs and initializes aPolyline2Dfrom the specified parameters.- Parameters:
xpoints- an array of x coordinatesypoints- an array of y coordinatesnpoints- the total number of points in thePolyline2D- 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.
-
Polyline2D
public Polyline2D(int[] xpoints, int[] ypoints, int npoints)Constructs and initializes aPolyline2Dfrom the specified parameters.- Parameters:
xpoints- an array of x coordinatesypoints- an array of y coordinatesnpoints- the total number of points in thePolyline2D- 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.
-
Polyline2D
public Polyline2D(java.awt.geom.Line2D line)
-
-
Method Detail
-
reset
public void reset()
Resets thisPolyline2Dobject 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 emptyPolyline2Dmight 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
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object
-
calculatePath
private void calculatePath()
-
updatePath
private void updatePath(float x, float y)
-
addPoint
public void addPoint(java.awt.geom.Point2D p)
-
addPoint
public void addPoint(float x, float y)Appends the specified coordinates to thisPolyline2D.If an operation that calculates the bounding box of this
Polyline2Dhas already been performed, such asgetBoundsorcontains, then this method updates the bounding box.- Parameters:
x- the specified x coordinatey- the specified y coordinate- See Also:
Polygon.getBounds(),Polygon.contains(double,double)
-
getBounds
public java.awt.Rectangle getBounds()
Gets the bounding box of thisPolyline2D. The bounding box is the smallestRectanglewhose sides are parallel to the x and y axes of the coordinate space, and can completely contain thePolyline2D.- Specified by:
getBoundsin interfacejava.awt.Shape- Returns:
- a
Rectanglethat defines the bounds of thisPolyline2D.
-
updateComputingPath
private void updateComputingPath()
-
contains
public boolean contains(java.awt.Point p)
Determines whether the specifiedPointis 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.- Specified by:
containsin interfacejava.awt.Shape
-
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
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.
-
contains
public boolean contains(java.awt.geom.Point2D p)
Tests if a specifiedPoint2Dis 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.- Specified by:
containsin interfacejava.awt.Shape
-
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 thisPolyline2Dentirely 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.- Specified by:
containsin interfacejava.awt.Shape
-
contains
public boolean contains(java.awt.geom.Rectangle2D r)
Tests if the interior of thisPolyline2Dentirely 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.- Specified by:
containsin interfacejava.awt.Shape
-
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.
-
getPolygon2D
public Polygon2D getPolygon2D()
-
getPathIterator
public java.awt.geom.PathIterator getPathIterator(java.awt.geom.AffineTransform at, double flatness)Returns an iterator object that iterates along the boundary of theShapeand 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, 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.
-
-