Class PathMeasure

java.lang.Object
icyllis.arc3d.core.PathMeasure
Direct Known Subclasses:
PathMeasure

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

  • 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

      public PathMeasure(Path path, boolean forceClose)
      This constructor assumes that resScale is 1.
      See Also:
    • PathMeasure

      public PathMeasure(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.
    • reset

      public boolean reset(Path path, boolean forceClose)
      This method assumes that resScale is 1.
      See Also:
    • reset

      public boolean reset(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.
      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 and 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
      positionOff - the starting index for position array
      tangent - if non-null, returns the sampled tangent vector
      tangentOff - the starting index for tangent array
      Returns:
      success or not
    • getMatrix

      @CheckReturnValue public boolean getMatrix(float distance, @Nullable Matrix matrix, int flags)
      Clamps distance between 0 and getContourLength(), and then computes the corresponding matrix (by calling getPosTan(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 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, 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 and 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 consumer that accepts path segments
      startWithMoveTo - true to add moveTo
      Returns:
      success or not
    • getTolerance

      public float getTolerance()
      Returns the tolerance, this is affected by resScale.