Class PathLength
java.lang.Object
org.apache.batik.ext.awt.geom.PathLength
Utilitiy class for length calculations of paths.
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.
- Version:
- $Id$
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA single path segment in the flattened version of the path.protected static classAPathIteratorthat returns only the next path segment from anotherPathIterator. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanWhether this path been flattened yet.protected ShapeThe path to use for calculations.protected floatCached copy of the path length.protected int[]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 insegmentsthat corresponds to that original path segment.protected ListThe list of flattened path segments. -
Constructor Summary
ConstructorsConstructorDescriptionPathLength(Shape path) Creates a new PathLength object for the specifiedShape. -
Method Summary
Modifier and TypeMethodDescriptionfloatangleAtLength(float length) Returns the slope of the path at the specified length.floatangleAtLength(int index, float proportion) Returns the slope of the path at the specified length.intfindUpperIndex(float length) Returns the index of the path segment that bounds the specified length along the path.floatgetLengthAtSegment(int index) Returns the length at the start of the segment given by the specified index.intReturns the number of segments in the path.getPath()Returns the path to use for calculations.protected voidFlattens the path and determines the path length.floatReturns the length of the path used by this PathLength object.pointAtLength(float length) Returns the point that is at the given length along the path.pointAtLength(int index, float proportion) Returns the point that is the given proportion along the path segment given by the specified index.intsegmentAtLength(float length) Returns the index of the segment at the given distance along the path.voidSets the path to use for calculations.
-
Field Details
-
path
The path to use for calculations. -
segments
The list of flattened path segments. -
segmentIndexes
protected int[] segmentIndexesArray where the index is the index of the original path segment and the value is the index of the first of the flattened segments insegmentsthat corresponds to that original path segment. -
pathLength
protected float pathLengthCached copy of the path length. -
initialised
protected boolean initialisedWhether this path been flattened yet.
-
-
Constructor Details
-
PathLength
-
-
Method Details
-
getPath
Returns the path to use for calculations.- Returns:
- Path used in calculations.
-
setPath
Sets the path to use for calculations.- Parameters:
v- Path to be used in calculations.
-
lengthOfPath
public float lengthOfPath()Returns the length of the path used by this PathLength object.- Returns:
- The length of the path.
-
initialise
protected void initialise()Flattens the path and determines the path length. -
getNumberOfSegments
public int getNumberOfSegments()Returns the number of segments in the path. -
getLengthAtSegment
public float getLengthAtSegment(int index) Returns the length at the start of the segment given by the specified index. -
segmentAtLength
public int segmentAtLength(float length) Returns the index of the segment at the given distance along the path. -
pointAtLength
Returns the point that is the given proportion along the path segment given by the specified index. -
pointAtLength
Returns the point that is at the given length along the path.- Parameters:
length- The length along the path- Returns:
- The point at the given length
-
angleAtLength
-
angleAtLength
-
findUpperIndex
public int findUpperIndex(float length) Returns the index of the path segment that bounds the specified length along the path.- Parameters:
length- The length along the path- Returns:
- The path segment index, or -1 if there is not such segment
-