# PathIterator

Artifact: [androidx.graphics:graphics-path](https://developer.android.com/jetpack/androidx/releases/graphics) [View Source](https://cs.android.com/search?q=file:androidx/graphics/path/PathIterator.kt+class:androidx.graphics.path.PathIterator) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

*** ** * ** ***


```
public final class PathIterator implements Iterator<@NonNull PathSegment>
```

<br />

*** ** * ** ***

A path iterator can be used to iterate over all the `https://developer.android.com/reference/androidx/graphics/path/PathSegment` 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 `https://developer.android.com/reference/androidx/graphics/path/PathIterator#conicEvaluation()` to `https://developer.android.com/reference/androidx/graphics/path/PathIterator.ConicEvaluation#AsConic`. The error of the approximation is controlled by `https://developer.android.com/reference/androidx/graphics/path/PathIterator#tolerance()`.

`https://developer.android.com/reference/androidx/graphics/path/PathIterator` objects are created implicitly through a given `https://developer.android.com/reference/android/graphics/Path.html` object; to create a `https://developer.android.com/reference/androidx/graphics/path/PathIterator`, call one of the two `https://developer.android.com/reference/androidx/graphics/path/package-summary#(android.graphics.Path).iterator()` extension functions.

## Summary

| ### Nested types |
|---|
| `public enum https://developer.android.com/reference/androidx/graphics/path/PathIterator.ConicEvaluation extends https://developer.android.com/reference/java/lang/Enum.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/path/PathIterator.ConicEvaluation>` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/graphics/path/PathIterator#PathIterator(android.graphics.Path,androidx.graphics.path.PathIterator.ConicEvaluation,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Path.html path, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/path/PathIterator.ConicEvaluation conicEvaluation, float tolerance )` |

| ### Public methods |
|---|---|
| `final int` | `https://developer.android.com/reference/androidx/graphics/path/PathIterator#calculateSize(kotlin.Boolean)(boolean includeConvertedConics)` Returns the number of verbs present in this iterator, i.e. the number of calls to `https://developer.android.com/reference/androidx/graphics/path/PathIterator#next(kotlin.FloatArray,kotlin.Int)` required to complete the iteration. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/path/PathIterator.ConicEvaluation` | `https://developer.android.com/reference/androidx/graphics/path/PathIterator#getConicEvaluation()()` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Path.html` | `https://developer.android.com/reference/androidx/graphics/path/PathIterator#getPath()()` |
| `final float` | `https://developer.android.com/reference/androidx/graphics/path/PathIterator#getTolerance()()` |
| `boolean` | `https://developer.android.com/reference/androidx/graphics/path/PathIterator#hasNext()()` Returns `true` if the iteration has more elements. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/path/PathSegment` | `https://developer.android.com/reference/androidx/graphics/path/PathIterator#next()()` Returns the next `https://developer.android.com/reference/androidx/graphics/path/PathSegment` in the iteration, or `https://developer.android.com/reference/androidx/graphics/path/package-summary#DoneSegment()` if the iteration is finished. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type` | `https://developer.android.com/reference/androidx/graphics/path/PathIterator#next(kotlin.FloatArray,kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/NonNull float[] points, int offset)` Returns the `https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type` of the next `https://developer.android.com/reference/androidx/graphics/path/PathSegment` in the iteration and fills `https://developer.android.com/reference/androidx/graphics/path/PathIterator#next(kotlin.FloatArray,kotlin.Int)` with the points specific to the segment type. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type` | `https://developer.android.com/reference/androidx/graphics/path/PathIterator#peek()()` Returns the type of the current segment in the iteration, or `https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type#Done` if the iteration is finished. |

### Inherited methods

From [kotlin.collections.Iterator](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterator/index.html) `void` `https://developer.android.com/reference/java/util/Iterator.html#forEachRemaining(java.util.function.Consumer&lt;? super E&gt;)(
@https://developer.android.com/reference/androidx/annotation/RecentlyNonNull @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/function/Consumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/path/PathSegment> action
)`

## Public constructors

### PathIterator

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

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

## Public methods

### calculateSize

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#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 `https://developer.android.com/reference/androidx/graphics/path/PathIterator#next(kotlin.FloatArray,kotlin.Int)` required to complete the iteration.

By default, `https://developer.android.com/reference/androidx/graphics/path/PathIterator#calculateSize(kotlin.Boolean)` returns the true number of operations in the iterator. Deriving this result requires converting any conics to quadratics, if `https://developer.android.com/reference/androidx/graphics/path/PathIterator#conicEvaluation()` is set to `https://developer.android.com/reference/androidx/graphics/path/PathIterator.ConicEvaluation#AsQuadratics`, which takes extra processing time. Set `https://developer.android.com/reference/androidx/graphics/path/PathIterator#calculateSize(kotlin.Boolean)` 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](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
public final @NonNull PathIterator.ConicEvaluation getConicEvaluation()
```

### getPath

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
public final @NonNull Path getPath()
```

### getTolerance

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
public final float getTolerance()
```

### hasNext

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
public boolean hasNext()
```

Returns `true` if the iteration has more elements.

### next

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
public @NonNull PathSegment next()
```

Returns the next `https://developer.android.com/reference/androidx/graphics/path/PathSegment` in the iteration, or `https://developer.android.com/reference/androidx/graphics/path/package-summary#DoneSegment()` if the iteration is finished. To save on allocations, use the alternative `https://developer.android.com/reference/androidx/graphics/path/PathIterator#next()` function, which takes a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html`.

### next

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

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

Returns the `https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type` of the next `https://developer.android.com/reference/androidx/graphics/path/PathSegment` in the iteration and fills `https://developer.android.com/reference/androidx/graphics/path/PathIterator#next(kotlin.FloatArray,kotlin.Int)` with the points specific to the segment type. Each pair of floats in the `https://developer.android.com/reference/androidx/graphics/path/PathIterator#next(kotlin.FloatArray,kotlin.Int)` array represents a point for the given segment. The number of pairs of floats depends on the `https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type`:

- `https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type#Move`: 1 pair (indices 0 to 1)

- `https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type#Line`: 2 pairs (indices 0 to 3)

- `https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type#Quadratic`: 3 pairs (indices 0 to 5)

- `https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type#Conic`: 3 pairs (indices 0 to 5), and the conic `https://developer.android.com/reference/androidx/graphics/path/PathSegment#weight()` at index 6. The value of the last float is undefined

- `https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type#Cubic`: 4 pairs (indices 0 to 7)

- `https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type#Close`: 0 pair

- `https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type#Done`: 0 pair This method does not allocate any memory.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull float[] points` | A `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html` large enough to hold 8 floats starting at `https://developer.android.com/reference/androidx/graphics/path/PathIterator#next(kotlin.FloatArray,kotlin.Int)`, throws an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` otherwise. |
| `int offset` | Offset in `https://developer.android.com/reference/androidx/graphics/path/PathIterator#next(kotlin.FloatArray,kotlin.Int)` where to store the result |

### peek

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
public final @NonNull PathSegment.Type peek()
```

Returns the type of the current segment in the iteration, or `https://developer.android.com/reference/androidx/graphics/path/PathSegment.Type#Done` if the iteration is finished.