PathIterator


public final class PathIterator implements Iterator


A path iterator can be used to iterate over all the segments that make up a path. Those segments may in turn define multiple contours inside the path. Conic segments are by default evaluated as approximated quadratic segments. To preserve conic segments as conics, set conicEvaluation to AsConic. The error of the approximation is controlled by tolerance.

PathIterator objects are created implicitly through a given Path object; to create a PathIterator, call one of the two Path.iterator extension functions.

Summary

Nested types

Public constructors

PathIterator(
    @NonNull Path path,
    @NonNull PathIterator.ConicEvaluation conicEvaluation,
    float tolerance
)

Public methods

final int
calculateSize(boolean includeConvertedConics)

Returns the number of verbs present in this iterator, i.e. the number of calls to next required to complete the iteration.

final @NonNull PathIterator.ConicEvaluation
final @NonNull Path
final float
boolean

Returns true if the iteration has more elements.

@NonNull PathSegment

Returns the next path segment in the iteration, or DoneSegment if the iteration is finished.

final @NonNull PathSegment.Type
next(@NonNull float[] points, int offset)

Returns the type of the next path segment in the iteration and fills points with the points specific to the segment type.

final @NonNull PathSegment.Type

Returns the type of the current segment in the iteration, or Done if the iteration is finished.

Public constructors

PathIterator

Added in 1.0.0
public PathIterator(
    @NonNull Path path,
    @NonNull PathIterator.ConicEvaluation conicEvaluation,
    float tolerance
)

Public methods

calculateSize

Added in 1.0.0
public final int calculateSize(boolean includeConvertedConics)

Returns the number of verbs present in this iterator, i.e. the number of calls to next required to complete the iteration.

By default, calculateSize returns the true number of operations in the iterator. Deriving this result requires converting any conics to quadratics, if conicEvaluation is set to ConicEvaluation.AsQuadratics, which takes extra processing time. Set includeConvertedConics to false if an approximate size, not including conic conversion, is sufficient.

Parameters
boolean includeConvertedConics

The returned size includes any required conic conversions. Default is true, so it will return the exact size, at the cost of iterating through all elements and converting any conics as appropriate. Set to false to save on processing, at the cost of a less exact result.

getConicEvaluation

Added in 1.0.0
public final @NonNull PathIterator.ConicEvaluation getConicEvaluation()

getPath

Added in 1.0.0
public final @NonNull Path getPath()

getTolerance

Added in 1.0.0
public final float getTolerance()

hasNext

Added in 1.0.0
public boolean hasNext()

Returns true if the iteration has more elements.

next

Added in 1.0.0
public @NonNull PathSegment next()

Returns the next path segment in the iteration, or DoneSegment if the iteration is finished. To save on allocations, use the alternative next function, which takes a FloatArray.

next

Added in 1.0.0
public final @NonNull PathSegment.Type next(@NonNull float[] points, int offset)

Returns the type of the next path segment in the iteration and fills points with the points specific to the segment type. Each pair of floats in the points array represents a point for the given segment. The number of pairs of floats depends on the PathSegment.Type:

  • Move: 1 pair (indices 0 to 1)

  • Line: 2 pairs (indices 0 to 3)

  • Quadratic: 3 pairs (indices 0 to 5)

  • Conic: 3 pairs (indices 0 to 5), and the conic weight at index 6. The value of the last float is undefined

  • Cubic: 4 pairs (indices 0 to 7)

  • Close: 0 pair

  • Done: 0 pair This method does not allocate any memory.

Parameters
@NonNull float[] points

A FloatArray large enough to hold 8 floats starting at offset, throws an IllegalStateException otherwise.

int offset

Offset in points where to store the result

peek

Added in 1.0.0
public final @NonNull PathSegment.Type peek()

Returns the type of the current segment in the iteration, or Done if the iteration is finished.