Class 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
Nested classes/interfaces inherited from class icyllis.arc3d.core.PathMeasure
PathMeasure.MatrixFlags
-
Field Summary
Fields inherited from class icyllis.arc3d.core.PathMeasure
MATRIX_FLAG_GET_POS_AND_TAN, MATRIX_FLAG_GET_POSITION, MATRIX_FLAG_GET_TANGENT, mTmp
-
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 andPathMeasure.getContourLength()
, and then computes the corresponding matrix (by callinggetPosTan(float, float[], float[])
).boolean
getPosTan
(float distance, float[] position, float[] tangent) Clamps distance between 0 andPathMeasure.getContourLength()
, and then computes the corresponding position and tangent vector (un-normalized).boolean
Clamps distance between 0 andPathMeasure.getContourLength()
, and then computes the corresponding position and tangent vector (un-normalized).boolean
getSegment
(float startDistance, float endDistance, Path dst, boolean startWithMoveTo) Given a start and end distance, return in dst the intervening segment(s).boolean
isClosed()
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.Methods inherited from class icyllis.arc3d.core.PathMeasure
getContourLength, getMatrix, getPosTan, getSegment, getTolerance, hasContour, isContourClosed, reset, reset
-
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.- Overrides:
reset
in classPathMeasure
-
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.- Overrides:
nextContour
in classPathMeasure
- See Also:
-
getLength
public float getLength()Returns the length of the current contour. -
isClosed
public boolean isClosed()Returns true if the current contour is closed. -
getPosTan
@CheckReturnValue public boolean getPosTan(float distance, @Nullable float[] position, @Nullable float[] tangent) Clamps distance between 0 andPathMeasure.getContourLength()
, 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 positiontangent
- if non-null, returns the sampled tangent vector- Returns:
- success or not
-
getPosTan
@CheckReturnValue public boolean getPosTan(float distance, @Nullable PointF position, @Nullable PointF tangent) Clamps distance between 0 andPathMeasure.getContourLength()
, 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 positiontangent
- if non-null, returns the sampled tangent vector- Returns:
- success or not
-
getMatrix
Clamps distance between 0 andPathMeasure.getContourLength()
, and then computes the corresponding matrix (by callinggetPosTan(float, float[], float[])
). 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, @NonNull Path 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 andPathMeasure.getContourLength()
. 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 that accepts path segmentsstartWithMoveTo
- true to add moveTo- Returns:
- success or not
-