# PathIterator

Artifact: [androidx.compose.ui:ui-graphics](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/graphics/PathIterator.kt+class:androidx.compose.ui.graphics.PathIterator) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0) Common/AllAndroid/JVM
- Cmn

  ```
  interface PathIterator : Iterator<PathSegment>
  ```

*** ** * ** ***

A path iterator can be used to iterate over all the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathSegment` that make up a path. Those segments may in turn define multiple contours inside the path.

The handling of conic segments is defined by the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator#conicEvaluation()` property. When set to `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator.ConicEvaluation#AsConic`, conic segments are preserved, but when set to `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator.ConicEvaluation#AsQuadratics`, conic segments are approximated using 1 or more quadratic segments. The error of the approximation is controlled by `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator#tolerance()`.

## Summary

| ### Nested types |
|---|
| `enum https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator.ConicEvaluation : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-enum/index.html<https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator.ConicEvaluation>` Used to define how conic segments are evaluated when iterating over a `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path` using `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator`. |

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/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/compose/ui/graphics/PathIterator#next(kotlin.FloatArray,kotlin.Int)` required to complete the iteration. | Cmn |
| `operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator#hasNext()()` Returns `true` if the iteration has more elements. | Cmn |
| `operator https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathSegment` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator#next()()` Returns the next `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathSegment` in the iteration, or `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/package-summary#DoneSegment()` if the iteration is finished. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathSegment.Type` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator#next(kotlin.FloatArray,kotlin.Int)(outPoints: 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/compose/ui/graphics/PathSegment.Type` of the next `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathSegment` in the iteration and fills `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator#next(kotlin.FloatArray,kotlin.Int)` with the points specific to the segment type. | Cmn |

| ### Public properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator.ConicEvaluation` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator#conicEvaluation()` Indicates whether conic segments, when present, are preserved as-is or converted to quadratic segments, using an approximation whose error is controlled by `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator#tolerance()`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator#path()` The `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path` this iterator iterates on. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator#tolerance()` Error of the approximation used to evaluate conic segments if they are converted to quadratics. | Cmn |

## Public functions

### calculateSize

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

By default, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/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/compose/ui/graphics/PathIterator#conicEvaluation()` is set to `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator.ConicEvaluation#AsQuadratics`, which takes extra processing time. Set `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/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

Cmn

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

Returns `true` if the iteration has more elements.

### next

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

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

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

### next

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

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

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

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

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

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

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

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

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

- `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathSegment.Type#Done`: 0 pair

This method does not allocate any memory.

| Parameters |
|---|---|
| `outPoints: 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/compose/ui/graphics/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/compose/ui/graphics/PathIterator#next(kotlin.FloatArray,kotlin.Int)` where to store the result |

## Public properties

### conicEvaluation

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

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

Indicates whether conic segments, when present, are preserved as-is or converted to quadratic segments, using an approximation whose error is controlled by `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator#tolerance()`.

### path

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
val path: Path
```

The `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path` this iterator iterates on.

### tolerance

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
val tolerance: Float
```

Error of the approximation used to evaluate conic segments if they are converted to quadratics. The error is defined as the maximum distance between the original conic segment and its quadratic approximation. See `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PathIterator#conicEvaluation()`.