Class PathMeasure
- Direct Known Subclasses:
PathMeasure
PathMeasure
provides measurements on segments of path contours
(lines, quadratic curves, cubic curves), such as determining the length of the path,
and/or finding the position and tangent along it.
A PathMeasure
object can be reused for measuring different Path
objects, by calling reset(Path, boolean, float)
.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
protected final float[]
-
Constructor Summary
ConstructorDescriptionCreate an empty PathMeasure object.PathMeasure
(Path path, boolean forceClose) This constructor assumes that resScale is 1.PathMeasure
(Path path, boolean forceClose, float resScale) Create a PathMeasure object associated with the specified path object. -
Method Summary
Modifier and TypeMethodDescriptionfloat
Returns the length of the current contour.boolean
Clamps distance between 0 andgetContourLength()
, and then computes the corresponding matrix (by callinggetPosTan(float, float[], int, float[], int)
).boolean
getPosTan
(float distance, float[] position, int positionOff, float[] tangent, int tangentOff) Clamps distance between 0 andgetContourLength()
, and then computes the corresponding position and tangent vector (un-normalized).boolean
getSegment
(float startDistance, float endDistance, PathConsumer dst, boolean startWithMoveTo) Given a start and end distance, return in dst the intervening segment(s).float
Returns the tolerance, this is affected by resScale.boolean
Returns true if there is a valid contour (length greater than 0).boolean
Returns true if the current contour is closed.boolean
Move to the next contour in the path and compute contour segments.void
reset()
Resets thisPathMeasure
object to its initial state, just like callingPathMeasure()
orreset(Path, boolean, float)
with an empty path.boolean
This method assumes that resScale is 1.boolean
Resets thisPathMeasure
object with a new path.
-
Field Details
-
MATRIX_FLAG_GET_POSITION
public static final int MATRIX_FLAG_GET_POSITION- See Also:
-
MATRIX_FLAG_GET_TANGENT
public static final int MATRIX_FLAG_GET_TANGENT- See Also:
-
MATRIX_FLAG_GET_POS_AND_TAN
public static final int MATRIX_FLAG_GET_POS_AND_TAN- See Also:
-
mTmp
protected final float[] mTmp
-
-
Constructor Details
-
PathMeasure
public PathMeasure()Create an empty PathMeasure object. -
PathMeasure
This constructor assumes that resScale is 1.- See Also:
-
PathMeasure
Create a PathMeasure object associated with the specified path object.This constructor makes a fast copy of path, then any modifications to path will not affect subsequent measurements.
resScale controls the precision of the measurement. For example, if you draw the measured path onto Canvas with a scale of 5.0, then resScale should also be set to 5.0. Values greater than 1 will increase precision, but also slow down the computation.
If forceClose is true, then the path will be considered as "closed" even if its contour was not explicitly closed.
-
-
Method Details
-
reset
public void reset()Resets thisPathMeasure
object to its initial state, just like callingPathMeasure()
orreset(Path, boolean, float)
with an empty path. This method releases the internal reference to the original path. -
reset
This method assumes that resScale is 1.- See Also:
-
reset
Resets thisPathMeasure
object with a new path.This method makes a fast copy of path, then any modifications to path will not affect subsequent measurements.
resScale controls the precision of the measurement. For example, if you draw the measured path onto Canvas with a scale of 5.0, then resScale should also be set to 5.0. Values greater than 1 will increase precision, but also slow down the computation.
If forceClose is true, then the path will be considered as "closed" even if its contour was not explicitly closed.
- Returns:
- true if there is a valid contour
-
nextContour
public boolean nextContour()Move to the next contour in the path and compute contour segments. Return true if one exists, or false if we're done with the path. If this method returns false, thenreset()
is called.- See Also:
-
hasContour
public boolean hasContour()Returns true if there is a valid contour (length greater than 0). -
getContourLength
public float getContourLength()Returns the length of the current contour. -
isContourClosed
public boolean isContourClosed()Returns true if the current contour is closed. -
getPosTan
@CheckReturnValue public boolean getPosTan(float distance, @Nullable float[] position, int positionOff, @Nullable float[] tangent, int tangentOff) Clamps distance between 0 andgetContourLength()
, and then computes the corresponding position and tangent vector (un-normalized). Returns false if there is no contour, or a zero-length path was specified, in which case position and tangent are unchanged.- Parameters:
distance
- the distance along the current contour to sampleposition
- if non-null, returns the sampled positionpositionOff
- the starting index for position arraytangent
- if non-null, returns the sampled tangent vectortangentOff
- the starting index for tangent array- Returns:
- success or not
-
getMatrix
Clamps distance between 0 andgetContourLength()
, and then computes the corresponding matrix (by callinggetPosTan(float, float[], int, float[], int)
). Returns false if there is no contour, or a zero-length path was specified, in which case matrix is unchanged.- Parameters:
distance
- the distance along the current contour to samplematrix
- if non-null, returns the transformationflags
- what aspects should be returned in the matrix- Returns:
- success or not
-
getSegment
@CheckReturnValue public boolean getSegment(float startDistance, float endDistance, PathConsumer dst, boolean startWithMoveTo) Given a start and end distance, return in dst the intervening segment(s). If the segment is zero-length, return false, else return true. startDistance and endDistance are clamped between 0 andgetContourLength()
. If startDistance > endDistance then return false (and leave dst untouched). Begin the segment with a moveTo if startWithMoveTo is true.- Parameters:
startDistance
- the start distance along the current contourendDistance
- the end distance along the current contourdst
- a path consumer that accepts path segmentsstartWithMoveTo
- true to add moveTo- Returns:
- success or not
-
getTolerance
public float getTolerance()Returns the tolerance, this is affected by resScale.
-