Package icyllis.modernui.graphics

# Class PathMeasure

java.lang.Object
icyllis.arc3d.core.PathMeasure
icyllis.modernui.graphics.PathMeasure

public class PathMeasure extends 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

  Constructors
  Constructor
  Description
  `PathMeasure()`
  Create 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 Type
  Method
  Description
  `float`
  `getLength()`
  Returns the length of the current contour.
  `boolean`
  `getMatrix(float distance, Matrix matrix, int flags)`
  Clamps distance between 0 and `PathMeasure.getContourLength()`, and then computes the corresponding matrix (by calling `getPosTan(float, float[], float[])`).
  `boolean`
  `getPosTan(float distance, float[] position, float[] tangent)`
  Clamps distance between 0 and `PathMeasure.getContourLength()`, and then computes the corresponding position and tangent vector (un-normalized).
  `boolean`
  `getPosTan(float distance, PointF position, PointF tangent)`
  Clamps distance between 0 and `PathMeasure.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`
  `nextContour()`
  Move to the next contour in the path and compute contour segments.
  `void`
  `reset()`
  Resets this `PathMeasure` object to its initial state, just like calling `PathMeasure()` or `reset(Path, boolean, float)` with an empty path.
  `boolean`
  `reset(Path path, boolean forceClose)`
  This method assumes that resScale is 1.
  `boolean`
  `reset(Path path, boolean forceClose, float resScale)`
  Resets this `PathMeasure` object with a new path.

  ### Methods inherited from class icyllis.arc3d.core.PathMeasure

  `getContourLength, getMatrix, getPosTan, getSegment, getTolerance, hasContour, isContourClosed, reset, reset`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### PathMeasure

    public PathMeasure()
    Create an empty PathMeasure object.

  - ### PathMeasure

    public PathMeasure(@Nullable Path path, boolean forceClose)
    This constructor assumes that resScale is 1.
    See Also:
      - `PathMeasure(Path, boolean, float)`

  - ### PathMeasure

    public PathMeasure(@Nullable Path path, boolean forceClose, float resScale)
    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 this `PathMeasure` object to its initial state, just like calling `PathMeasure()` or `reset(Path, boolean, float)` with an empty path. This method releases the internal reference to the original path.
    Overrides:
      `reset` in class `PathMeasure`

  - ### reset

    public boolean reset(@Nullable Path path, boolean forceClose)
    This method assumes that resScale is 1.
    See Also:
      - `reset(Path, boolean, float)`

  - ### reset

    public boolean reset(@Nullable Path path, boolean forceClose, float resScale)
    Resets this `PathMeasure` 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, then `reset()` is called.
    Overrides:
      `nextContour` in class `PathMeasure`
    See Also:
      - `PathMeasure.hasContour()`

  - ### 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 and `PathMeasure.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 sample
      `position` - if non-null, returns the sampled position
      `tangent` - 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 and `PathMeasure.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 sample
      `position` - if non-null, returns the sampled position
      `tangent` - if non-null, returns the sampled tangent vector
    Returns:
      success or not

  - ### getMatrix

    @CheckReturnValue public boolean getMatrix(float distance, @Nullable Matrix matrix, int flags)
    Clamps distance between 0 and `PathMeasure.getContourLength()`, and then computes the corresponding matrix (by calling `getPosTan(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 sample
      `matrix` - if non-null, returns the transformation
      `flags` - 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 and `PathMeasure.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 contour
      `endDistance` - the end distance along the current contour
      `dst` - a path that accepts path segments
      `startWithMoveTo` - true to add moveTo
    Returns:
      success or not