# Stroke

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

*** ** * ** ***

Common/All
- Cmn

  ```
  class Stroke
  ```

*** ** * ** ***

An immutable object comprised of a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch` that represents a user-drawn (or sometimes synthetic) path, a `https://developer.android.com/reference/kotlin/androidx/ink/brush/Brush` that contains information on how that path should be converted into a geometric shape and rendered on screen, and a `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh` which is the geometric shape calculated from the combination of the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch` and the `https://developer.android.com/reference/kotlin/androidx/ink/brush/Brush`.

This can be constructed directly from a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch` that has already been completed. To construct a stroke incrementally and render it as input events are received in real time, use `androidx.ink.authoring.InProgressStrokesView` or `https://developer.android.com/reference/kotlin/androidx/ink/strokes/InProgressStroke`, which will ultimately return a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` when input is completed.

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#Stroke(androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch)(brush: https://developer.android.com/reference/kotlin/androidx/ink/brush/Brush, inputs: https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch)` Construct a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` given a `https://developer.android.com/reference/kotlin/androidx/ink/brush/Brush` and a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch`, generating its `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#shape()`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#Stroke(androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)(brush: https://developer.android.com/reference/kotlin/androidx/ink/brush/Brush, inputs: https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch, shape: https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh)` Construct a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` given a `https://developer.android.com/reference/kotlin/androidx/ink/brush/Brush`, a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch`, and a `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh`. | Cmn |

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#copy(androidx.ink.brush.Brush)(brush: https://developer.android.com/reference/kotlin/androidx/ink/brush/Brush)` Returns a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` with the brush replaced. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke>` | `@https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#split(androidx.ink.geometry.AffineTransform,kotlin.Float)(strokeToWorldTransform: https://developer.android.com/reference/kotlin/androidx/ink/geometry/AffineTransform, tolerance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Splits this stroke into a set of spatially disconnected `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke`s. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` | `@https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#subtract(androidx.ink.geometry.PartitionedMesh,androidx.ink.geometry.AffineTransform,androidx.ink.geometry.AffineTransform)( maskShape: https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh, maskToWorldTransform: https://developer.android.com/reference/kotlin/androidx/ink/geometry/AffineTransform, strokeToWorldTransform: https://developer.android.com/reference/kotlin/androidx/ink/geometry/AffineTransform )` Subtracts `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#subtract(androidx.ink.geometry.PartitionedMesh,androidx.ink.geometry.AffineTransform,androidx.ink.geometry.AffineTransform)` from this stroke and returns the remaining portion as a new `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke`. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#toString()()` | Cmn |

| ### Public properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/brush/Brush` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#brush()` Contains information on how the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#(kotlin.Function0,androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)` should be used to calculate the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#(kotlin.Function0,androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)` and how that `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#(kotlin.Function0,androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)` should be drawn on screen. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/ink/strokes/ImmutableStrokeInputBatch` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#inputs()` The user-drawn (or perhaps synthetically generated) path that this `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` takes. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#shape()` The geometric shape of the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke`, which can be used to render it on screen and to perform geometric calculations. | Cmn |

## Public constructors

### Stroke

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

```
Stroke(brush: Brush, inputs: StrokeInputBatch)
```

Construct a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` given a `https://developer.android.com/reference/kotlin/androidx/ink/brush/Brush` and a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch`, generating its `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#shape()`.

### Stroke

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

```
Stroke(brush: Brush, inputs: StrokeInputBatch, shape: PartitionedMesh)
```

Construct a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` given a `https://developer.android.com/reference/kotlin/androidx/ink/brush/Brush`, a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch`, and a `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh`.

Note that this does not do any validation that `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#(androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)` and `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#(androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)` together would produce `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#(androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)`. This constructor is primarily intended for deserialization, in cases where the `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh` is being stored in addition to the `https://developer.android.com/reference/kotlin/androidx/ink/brush/Brush` and `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch`.

## Public functions

### copy

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

```
fun copy(brush: Brush): Stroke
```

Returns a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` with the brush replaced. This may or may not affect the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#shape()`, but will not change the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#inputs()`.

### split

Cmn Added in [1.1.0-alpha11](https://developer.android.com/jetpack/androidx/releases/ink#1.1.0-alpha11)

```
@WorkerThread
fun split(strokeToWorldTransform: AffineTransform, tolerance: Float): Set<Stroke>
```

Splits this stroke into a set of spatially disconnected `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke`s.

Two regions of the stroke are considered disconnected if they are further than `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#split(androidx.ink.geometry.AffineTransform,kotlin.Float)` distance apart, applying the given `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#split(androidx.ink.geometry.AffineTransform,kotlin.Float)`.

The `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#split(androidx.ink.geometry.AffineTransform,kotlin.Float)` parameter is useful to prevent the over-splitting of strokes. This helps maintain continuity in strokes that inherently contain geometric gaps (such as particle brushes), or in solid strokes where minor unintentional gaps are introduced (for example by glancing erases). For splitting a stroke that has been partially erased (with `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#subtract(androidx.ink.geometry.PartitionedMesh,androidx.ink.geometry.AffineTransform,androidx.ink.geometry.AffineTransform)`) by eraser strokes, it may be natural to set `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#split(androidx.ink.geometry.AffineTransform,kotlin.Float)` to the size of the eraser brush.

Each resulting stroke has a new shape representing its portion, but retains the original `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#inputs()` and `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#brush()`. Each returned stroke can have its brush color updated (with brush `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#copy(androidx.ink.brush.Brush)`), but modifying other properties (like brush size) will revert the stroke to the shape of the original stroke.

Note that `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#split(androidx.ink.geometry.AffineTransform,kotlin.Float)` can be a computationally expensive geometric operation, and should generally be performed on a background (worker) thread to avoid blocking the UI thread.

| Parameters |
|---|---|
| `strokeToWorldTransform: https://developer.android.com/reference/kotlin/androidx/ink/geometry/AffineTransform` | The `https://developer.android.com/reference/kotlin/androidx/ink/geometry/AffineTransform` from stroke coordinates to world coordinates. |
| `tolerance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The maximum distance in world coordinates between two points to consider them connected. |

### subtract

Cmn Added in [1.1.0-alpha11](https://developer.android.com/jetpack/androidx/releases/ink#1.1.0-alpha11)

```
@WorkerThread
fun subtract(
    maskShape: PartitionedMesh,
    maskToWorldTransform: AffineTransform,
    strokeToWorldTransform: AffineTransform
): Stroke
```

Subtracts `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#subtract(androidx.ink.geometry.PartitionedMesh,androidx.ink.geometry.AffineTransform,androidx.ink.geometry.AffineTransform)` from this stroke and returns the remaining portion as a new `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke`.

The returned stroke has a newly computed `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#shape()` representing the shape after subtraction, but retains the original `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#inputs()` and `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#brush()`. The stroke can have its brush color updated (with `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#copy(androidx.ink.brush.Brush)`), but modifying other properties (like brush size) will revert the stroke to its original shape and undo the subtraction. The stroke may be empty or contain disconnected geometry -- to separate disconnected regions into independent `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` instances, call `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#split(androidx.ink.geometry.AffineTransform,kotlin.Float)`.

Note that `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#subtract(androidx.ink.geometry.PartitionedMesh,androidx.ink.geometry.AffineTransform,androidx.ink.geometry.AffineTransform)` can be a computationally expensive geometric operation, and should generally be performed on a background (worker) thread to avoid blocking the UI thread.

| Parameters |
|---|---|
| `maskShape: https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh` | A `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh` representing the geometric region to be subtracted. |
| `maskToWorldTransform: https://developer.android.com/reference/kotlin/androidx/ink/geometry/AffineTransform` | The `https://developer.android.com/reference/kotlin/androidx/ink/geometry/AffineTransform` from mask coordinates to world coordinates. |
| `strokeToWorldTransform: https://developer.android.com/reference/kotlin/androidx/ink/geometry/AffineTransform` | The `https://developer.android.com/reference/kotlin/androidx/ink/geometry/AffineTransform` from stroke coordinates to world coordinates. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` | The `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` remaining after the subtraction. |

### toString

Cmn

```
open fun toString(): String
```

## Public properties

### brush

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

```
val brush: Brush
```

Contains information on how the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#(kotlin.Function0,androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)` should be used to calculate the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#(kotlin.Function0,androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)` and how that `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#(kotlin.Function0,androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)` should be drawn on screen.

### inputs

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

```
val inputs: ImmutableStrokeInputBatch
```

The user-drawn (or perhaps synthetically generated) path that this `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke` takes.

### shape

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

```
val shape: PartitionedMesh
```

The geometric shape of the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke`, which can be used to render it on screen and to perform geometric calculations. This `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh` will have one render group per brush coat in `https://developer.android.com/reference/kotlin/androidx/ink/strokes/Stroke#brush()`.