# 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)

*** ** * ** ***


```
class PathIterator : Iterator<PathSegment>
```

<br />

*** ** * ** ***

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

`https://developer.android.com/reference/kotlin/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/kotlin/androidx/graphics/path/PathIterator`, call one of the two `https://developer.android.com/reference/kotlin/androidx/graphics/path/package-summary#(android.graphics.Path).iterator()` extension functions.

## Summary

| ### Nested types |
|---|
| `enum https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator.ConicEvaluation : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-enum/index.html<https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator.ConicEvaluation>` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#PathIterator(android.graphics.Path,androidx.graphics.path.PathIterator.ConicEvaluation,kotlin.Float)( path: https://developer.android.com/reference/android/graphics/Path.html, conicEvaluation: https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator.ConicEvaluation, tolerance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#calculateSize(kotlin.Boolean)(includeConvertedConics: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Returns the number of verbs present in this iterator, i.e. the number of calls to `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#next(kotlin.FloatArray,kotlin.Int)` required to complete the iteration. |
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#hasNext()()` Returns `true` if the iteration has more elements. |
| `open operator https://developer.android.com/reference/kotlin/androidx/graphics/path/PathSegment` | `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#next()()` Returns the next `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathSegment` in the iteration, or `https://developer.android.com/reference/kotlin/androidx/graphics/path/package-summary#DoneSegment()` if the iteration is finished. |
| `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathSegment.Type` | `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#next(kotlin.FloatArray,kotlin.Int)(points: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html, offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathSegment.Type` of the next `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathSegment` in the iteration and fills `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#next(kotlin.FloatArray,kotlin.Int)` with the points specific to the segment type. |
| `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathSegment.Type` | `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#peek()()` Returns the type of the current segment in the iteration, or `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathSegment.Type#Done` if the iteration is finished. |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator.ConicEvaluation` | `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#conicEvaluation()` |
| `https://developer.android.com/reference/android/graphics/Path.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#path()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#tolerance()` |

### Inherited functions

From [kotlin.collections.Iterator](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterator/index.html) `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterator/for-each-remaining.html(@https://developer.android.com/reference/kotlin/androidx/annotation/RecentlyNonNull action: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/graphics/path/PathSegment>)`

## Public constructors

### PathIterator

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

```
PathIterator(
    path: Path,
    conicEvaluation: PathIterator.ConicEvaluation = ConicEvaluation.AsQuadratics,
    tolerance: Float = 0.25f
)
```

## Public functions

### calculateSize

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

```
fun calculateSize(includeConvertedConics: Boolean = true): Int
```

Returns the number of verbs present in this iterator, i.e. the number of calls to `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#next(kotlin.FloatArray,kotlin.Int)` required to complete the iteration.

By default, `https://developer.android.com/reference/kotlin/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/kotlin/androidx/graphics/path/PathIterator#conicEvaluation()` is set to `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator.ConicEvaluation#AsQuadratics`, which takes extra processing time. Set `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathIterator#calculateSize(kotlin.Boolean)` to false if an approximate size, not including conic conversion, is sufficient.

| Parameters |
|---|---|
| `includeConvertedConics: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = true` | 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. |

### hasNext

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

```
open operator fun hasNext(): Boolean
```

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)

```
open operator fun next(): PathSegment
```

Returns the next `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathSegment` in the iteration, or `https://developer.android.com/reference/kotlin/androidx/graphics/path/package-summary#DoneSegment()` if the iteration is finished. To save on allocations, use the alternative `https://developer.android.com/reference/kotlin/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)

```
fun next(points: FloatArray, offset: Int = 0): PathSegment.Type
```

Returns the `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathSegment.Type` of the next `https://developer.android.com/reference/kotlin/androidx/graphics/path/PathSegment` in the iteration and fills `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/androidx/graphics/path/PathSegment.Type`:

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

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

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

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

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

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

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

| Parameters |
|---|---|
| `points: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html` | 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/kotlin/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. |
| `offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | Offset in `https://developer.android.com/reference/kotlin/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)

```
fun peek(): PathSegment.Type
```

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

## Public properties

### conicEvaluation

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

```
val conicEvaluation: PathIterator.ConicEvaluation
```

### path

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

```
val path: Path
```

### tolerance

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

```
val tolerance: Float
```