public class DefaultPathLength extends java.lang.Object implements PathLength
PathLength is a utility class for calculating the length of a path, the location of a point at a particular length along the path, and the angle of the tangent to the path at a given length.
It uses a FlatteningPathIterator to create a flattened version of the Path. This means the values returned are not always exact (in fact, they rarely are), but in most cases they are reasonably accurate.
Modifier and Type | Class and Description |
---|---|
protected static class |
DefaultPathLength.PathSegment
A single path segment in the flattened version of the path.
|
protected static class |
DefaultPathLength.SingleSegmentPathIterator
A
PathIterator that returns only the next path segment from
another PathIterator . |
Modifier and Type | Field and Description |
---|---|
protected boolean |
initialised
Whether this path been flattened yet.
|
protected java.awt.Shape |
path
The path to use for calculations.
|
protected float |
pathLength
Cached copy of the path length.
|
protected int[] |
segmentIndexes
Array where the index is the index of the original path segment
and the value is the index of the first of the flattened segments
in
segments that corresponds to that original path segment. |
protected java.util.List |
segments
The list of flattened path segments.
|
Constructor and Description |
---|
DefaultPathLength(java.awt.Shape path)
Creates a new PathLength object for the specified
Shape . |
Modifier and Type | Method and Description |
---|---|
float |
angleAtLength(float length)
Returns the slope of the path at the specified length.
|
float |
angleAtLength(int index,
float proportion)
Returns the slope of the path at the specified length.
|
int |
findUpperIndex(float length)
Returns the index of the path segment that bounds the specified
length along the path.
|
float |
getLengthAtSegment(int index)
Returns the length at the start of the segment given by the specified
index.
|
int |
getNumberOfSegments()
Returns the number of segments in the path.
|
java.awt.Shape |
getPath()
Returns the path to use for calculations.
|
protected void |
initialise()
Flattens the path and determines the path length.
|
float |
lengthOfPath()
Returns the length of the path used by this PathLength object.
|
java.awt.geom.Point2D |
pointAtLength(float length)
Returns the point that is at the given length along the path.
|
java.awt.geom.Point2D |
pointAtLength(int index,
float proportion)
Returns the point that is the given proportion along the path segment
given by the specified index.
|
int |
segmentAtLength(float length)
Returns the index of the segment at the given distance along the path.
|
void |
setPath(java.awt.Shape v)
Sets the path to use for calculations.
|
protected java.awt.Shape path
protected java.util.List segments
protected int[] segmentIndexes
segments
that corresponds to that original path segment.protected float pathLength
protected boolean initialised
public DefaultPathLength(java.awt.Shape path)
Shape
.path
- The Path (or Shape) to use.public java.awt.Shape getPath()
public void setPath(java.awt.Shape v)
v
- Path to be used in calculations.public float lengthOfPath()
lengthOfPath
in interface PathLength
protected void initialise()
public int getNumberOfSegments()
public float getLengthAtSegment(int index)
public int segmentAtLength(float length)
public java.awt.geom.Point2D pointAtLength(int index, float proportion)
public java.awt.geom.Point2D pointAtLength(float length)
pointAtLength
in interface PathLength
length
- The length along the pathpublic float angleAtLength(int index, float proportion)
index
- The segment numberproportion
- The proportion along the given segmentMath.PI
,
Math.PI
].public float angleAtLength(float length)
angleAtLength
in interface PathLength
length
- The length along the pathMath.PI
,
Math.PI
].public int findUpperIndex(float length)
length
- The length along the path