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

*** ** * ** ***


```
public final class Stroke
```

<br />

*** ** * ** ***

An immutable object comprised of a `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` that represents a user-drawn (or sometimes synthetic) path, a `https://developer.android.com/reference/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/androidx/ink/geometry/PartitionedMesh` which is the geometric shape calculated from the combination of the `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch` and the `https://developer.android.com/reference/androidx/ink/brush/Brush`.

This can be constructed directly from a `https://developer.android.com/reference/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/androidx/ink/strokes/InProgressStroke`, which will ultimately return a `https://developer.android.com/reference/androidx/ink/strokes/Stroke` when input is completed.

## Summary

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

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/Stroke` | `https://developer.android.com/reference/androidx/ink/strokes/Stroke#copy(androidx.ink.brush.Brush)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/Brush brush)` Returns a `https://developer.android.com/reference/androidx/ink/strokes/Stroke` with the brush replaced. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/Brush` | `https://developer.android.com/reference/androidx/ink/strokes/Stroke#getBrush()()` Contains information on how the `https://developer.android.com/reference/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/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/androidx/ink/strokes/Stroke#(kotlin.Function0,androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)` should be drawn on screen. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/ImmutableStrokeInputBatch` | `https://developer.android.com/reference/androidx/ink/strokes/Stroke#getInputs()()` The user-drawn (or perhaps synthetically generated) path that this `https://developer.android.com/reference/androidx/ink/strokes/Stroke` takes. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/PartitionedMesh` | `https://developer.android.com/reference/androidx/ink/strokes/Stroke#getShape()()` The geometric shape of the `https://developer.android.com/reference/androidx/ink/strokes/Stroke`, which can be used to render it on screen and to perform geometric calculations. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/Stroke>` | `@https://developer.android.com/reference/androidx/annotation/WorkerThread https://developer.android.com/reference/androidx/ink/strokes/Stroke#split(androidx.ink.geometry.AffineTransform,kotlin.Float)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/AffineTransform strokeToWorldTransform, float tolerance)` Splits this stroke into a set of spatially disconnected `https://developer.android.com/reference/androidx/ink/strokes/Stroke`s. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/strokes/Stroke` | `@https://developer.android.com/reference/androidx/annotation/WorkerThread https://developer.android.com/reference/androidx/ink/strokes/Stroke#subtract(androidx.ink.geometry.PartitionedMesh,androidx.ink.geometry.AffineTransform,androidx.ink.geometry.AffineTransform)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/PartitionedMesh maskShape, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/AffineTransform maskToWorldTransform, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/AffineTransform strokeToWorldTransform )` Subtracts `https://developer.android.com/reference/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/androidx/ink/strokes/Stroke`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/ink/strokes/Stroke#toString()()` |

## Public constructors

### Stroke

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

```
public Stroke(@NonNull Brush brush, @NonNull StrokeInputBatch inputs)
```

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

### Stroke

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

```
public Stroke(
    @NonNull Brush brush,
    @NonNull StrokeInputBatch inputs,
    @NonNull PartitionedMesh shape
)
```

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

Note that this does not do any validation that `https://developer.android.com/reference/androidx/ink/strokes/Stroke#(androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)` and `https://developer.android.com/reference/androidx/ink/strokes/Stroke#(androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)` together would produce `https://developer.android.com/reference/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/androidx/ink/geometry/PartitionedMesh` is being stored in addition to the `https://developer.android.com/reference/androidx/ink/brush/Brush` and `https://developer.android.com/reference/androidx/ink/strokes/StrokeInputBatch`.

## Public methods

### copy

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

```
public final @NonNull Stroke copy(@NonNull Brush brush)
```

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

### getBrush

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

```
public final @NonNull Brush getBrush()
```

Contains information on how the `https://developer.android.com/reference/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/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/androidx/ink/strokes/Stroke#(kotlin.Function0,androidx.ink.brush.Brush,androidx.ink.strokes.StrokeInputBatch,androidx.ink.geometry.PartitionedMesh)` should be drawn on screen.

### getInputs

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

```
public final @NonNull ImmutableStrokeInputBatch getInputs()
```

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

### getShape

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

```
public final @NonNull PartitionedMesh getShape()
```

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

### split

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

```
@WorkerThread
public final @NonNull Set<@NonNull Stroke> split(@NonNull AffineTransform strokeToWorldTransform, float tolerance)
```

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

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

The `https://developer.android.com/reference/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/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/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/androidx/ink/strokes/Stroke#inputs()` and `https://developer.android.com/reference/androidx/ink/strokes/Stroke#brush()`. Each returned stroke can have its brush color updated (with brush `https://developer.android.com/reference/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/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/AffineTransform strokeToWorldTransform` | The `https://developer.android.com/reference/androidx/ink/geometry/AffineTransform` from stroke coordinates to world coordinates. |
| `float tolerance` | The maximum distance in world coordinates between two points to consider them connected. |

### subtract

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

```
@WorkerThread
public final @NonNull Stroke subtract(
    @NonNull PartitionedMesh maskShape,
    @NonNull AffineTransform maskToWorldTransform,
    @NonNull AffineTransform strokeToWorldTransform
)
```

Subtracts `https://developer.android.com/reference/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/androidx/ink/strokes/Stroke`.

The returned stroke has a newly computed `https://developer.android.com/reference/androidx/ink/strokes/Stroke#shape()` representing the shape after subtraction, but retains the original `https://developer.android.com/reference/androidx/ink/strokes/Stroke#inputs()` and `https://developer.android.com/reference/androidx/ink/strokes/Stroke#brush()`. The stroke can have its brush color updated (with `https://developer.android.com/reference/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/androidx/ink/strokes/Stroke` instances, call `https://developer.android.com/reference/androidx/ink/strokes/Stroke#split(androidx.ink.geometry.AffineTransform,kotlin.Float)`.

Note that `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/PartitionedMesh maskShape` | A `https://developer.android.com/reference/androidx/ink/geometry/PartitionedMesh` representing the geometric region to be subtracted. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/AffineTransform maskToWorldTransform` | The `https://developer.android.com/reference/androidx/ink/geometry/AffineTransform` from mask coordinates to world coordinates. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/geometry/AffineTransform strokeToWorldTransform` | The `https://developer.android.com/reference/androidx/ink/geometry/AffineTransform` from stroke coordinates to world coordinates. |

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

### toString

```
public @NonNull String toString()
```