# StrokeInputBatch

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/StrokeInputBatch.kt+class:androidx.ink.strokes.StrokeInputBatch) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

*** ** * ** ***

Common/All
- Cmn

  ```
  abstract class StrokeInputBatch
  ```
Known direct subclasses [ImmutableStrokeInputBatch](https://developer.android.com/reference/kotlin/androidx/ink/strokes/ImmutableStrokeInputBatch), [MutableStrokeInputBatch](https://developer.android.com/reference/kotlin/androidx/ink/strokes/MutableStrokeInputBatch)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/strokes/ImmutableStrokeInputBatch` | An immutable implementation of `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch`. |
| `https://developer.android.com/reference/kotlin/androidx/ink/strokes/MutableStrokeInputBatch` | A mutable implementation of `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch`. |

*** ** * ** ***

A read-only view of an object that stores multiple `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput` values together in a more memory-efficient manner than just `List<StrokeInput>`. The input points in this batch are guaranteed to be consistent with one another -- for example, they all have the same `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput#toolType()` and the same set of optional fields like pressure/tilt/orientation/twist, and their timestamps are all monotonically non-decreasing. This can be an `https://developer.android.com/reference/kotlin/androidx/ink/strokes/ImmutableStrokeInputBatch` for data that cannot change, or a `https://developer.android.com/reference/kotlin/androidx/ink/strokes/MutableStrokeInputBatch` for data that is meant to be modified or incrementally built.

## Summary

| ### Nested types |
|---|
| `object https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch.Companion` |

| ### Public functions |
|---|---|---|
| `operator https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#get(kotlin.Int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Gets the value of the i-th input. | Cmn |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0, toInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#getBasePaintAnimationPhase()()` Returns the \[0, 1) value that will determine the stroke's overall paint animation progress at some arbitrary zero clock state, so that different strokes can be animated correctly relative to each other. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#getDurationMillis()()` The duration between the first and last input in milliseconds. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#getNoiseSeed()()` Returns the seed value that should be used for seeding any noise generators for brush behaviors when a full stroke is regenerated with this input batch. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#getStrokeUnitLengthCm()()` The physical distance in centimeters that the pointer must travel in order to produce an input motion of one stroke unit. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/ink/brush/InputToolType` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#getToolType()()` How this input stream should be interpreted, as coming from a `https://developer.android.com/reference/kotlin/androidx/ink/brush/InputToolType#MOUSE()`, `https://developer.android.com/reference/kotlin/androidx/ink/brush/InputToolType#TOUCH()`, or `https://developer.android.com/reference/kotlin/androidx/ink/brush/InputToolType#STYLUS()`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#hasOrientation()()` Whether all of the individual inputs have a defined value for `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput#orientationRadians()`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#hasPressure()()` Whether all of the individual inputs have a defined value for `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput#pressure()`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#hasStrokeUnitLength()()` Whether `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput#strokeUnitLengthCm()` has a valid value, which is something other than `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput#NO_STROKE_UNIT_LENGTH()`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#hasTilt()()` Whether all of the individual inputs have a defined value for `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput#tiltRadians()`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#isEmpty()()` `true` if there are no `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput` objects in the batch, and `false` otherwise. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#populate(kotlin.Int,androidx.ink.strokes.StrokeInput)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, outStrokeInput: https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput)` Gets the value of the i-th input and overwrites `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#populate(kotlin.Int,androidx.ink.strokes.StrokeInput)`, which it then returns. | Cmn |
| `abstract https://developer.android.com/reference/kotlin/androidx/ink/strokes/ImmutableStrokeInputBatch` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#toImmutable()()` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#size()` Number of `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput` objects in the batch. | Cmn |

| ### Extension functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch.https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#(androidx.ink.strokes.StrokeInputBatch).createClosedShape()()` Creates a `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh` of the shape enclosed by the given `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch` input points. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch.https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#(androidx.ink.strokes.StrokeInputBatch).encode()()` Write a gzip-compressed `ink.proto.CodedStrokeInputBatch` binary proto message representing the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch` to the given `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html`. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch.https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#(androidx.ink.strokes.StrokeInputBatch).encode(java.io.OutputStream)(output: https://developer.android.com/reference/java/io/OutputStream.html)` Write a gzip-compressed `ink.proto.CodedStrokeInputBatch` binary proto message representing the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch` to the given `https://developer.android.com/reference/java/io/OutputStream.html`. | android |

## Public functions

### get

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

```
operator fun get(index: Int): StrokeInput
```

Gets the value of the i-th input. Requires that `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#get(kotlin.Int)` is non-negative and less than `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#size()`.

In performance-sensitive code, prefer to use `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#populate(kotlin.Int,androidx.ink.strokes.StrokeInput)` to pass in a pre-allocated instance and reuse that instance across multiple calls to this function.

### getBasePaintAnimationPhase

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

```
fun getBasePaintAnimationPhase(): @FloatRange(from = 0.0, to = 1.0, toInclusive = false) Float
```

Returns the \[0, 1) value that will determine the stroke's overall paint animation progress at some arbitrary zero clock state, so that different strokes can be animated correctly relative to each other.

### getDurationMillis

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

```
fun getDurationMillis(): Long
```

The duration between the first and last input in milliseconds.

### getNoiseSeed

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

```
fun getNoiseSeed(): Int
```

Returns the seed value that should be used for seeding any noise generators for brush behaviors when a full stroke is regenerated with this input batch. If no seed value has yet been set for this input batch, returns the default seed of zero.

### getStrokeUnitLengthCm

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

```
fun getStrokeUnitLengthCm(): Float
```

The physical distance in centimeters that the pointer must travel in order to produce an input motion of one stroke unit. For stylus/touch, this is the real-world distance that the stylus/fingertip must move in physical space; for mouse, this is the visual distance that the mouse pointer must travel along the surface of the display.

A value of `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput#NO_STROKE_UNIT_LENGTH()` indicates that the relationship between stroke space and physical space is unknown or ill-defined.

### getToolType

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

```
fun getToolType(): InputToolType
```

How this input stream should be interpreted, as coming from a `https://developer.android.com/reference/kotlin/androidx/ink/brush/InputToolType#MOUSE()`, `https://developer.android.com/reference/kotlin/androidx/ink/brush/InputToolType#TOUCH()`, or `https://developer.android.com/reference/kotlin/androidx/ink/brush/InputToolType#STYLUS()`.

### hasOrientation

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

```
fun hasOrientation(): Boolean
```

Whether all of the individual inputs have a defined value for `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput#orientationRadians()`. If not, then no input items have an orientation value.

### hasPressure

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

```
fun hasPressure(): Boolean
```

Whether all of the individual inputs have a defined value for `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput#pressure()`. If not, then no input items have a pressure value.

### hasStrokeUnitLength

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

```
fun hasStrokeUnitLength(): Boolean
```

Whether `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput#strokeUnitLengthCm()` has a valid value, which is something other than `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput#NO_STROKE_UNIT_LENGTH()`.

### hasTilt

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

```
fun hasTilt(): Boolean
```

Whether all of the individual inputs have a defined value for `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput#tiltRadians()`. If not, then no input items have a tilt value.

### isEmpty

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

```
fun isEmpty(): Boolean
```

`true` if there are no `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput` objects in the batch, and `false` otherwise.

### populate

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

```
fun populate(index: Int, outStrokeInput: StrokeInput): StrokeInput
```

Gets the value of the i-th input and overwrites `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#populate(kotlin.Int,androidx.ink.strokes.StrokeInput)`, which it then returns. Requires that `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#populate(kotlin.Int,androidx.ink.strokes.StrokeInput)` is non-negative and less than `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch#size()`.

### toImmutable

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

```
abstract fun toImmutable(): ImmutableStrokeInputBatch
```

## Public properties

### size

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

```
val size: Int
```

Number of `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInput` objects in the batch.

## Extension functions

### StrokeInputBatch.createClosedShape

Cmn 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/MeshCreation.kt+function:createClosedShape)

```
fun StrokeInputBatch.createClosedShape(): PartitionedMesh
```

Creates a `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh` of the shape enclosed by the given `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch` input points. A typical use case is selecting a region of the scene and performing hit testing with the resulting `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh`.

For a given stroke this algorithm aims to:

1. Identify and create any connections that the user may have intended to make but did not fully connect.

2. Trim any extra end points that the user did not intend to be part of the selected area.

Example usage:

```kotlin
fun onStrokeFinished(stroke: Stroke) {
   val selectionRegion = stroke.inputs.createClosedShape()
   for (stroke in myScene.strokes) {
       if (stroke.shape.intersects(selectionRegion)) {
           myScene.setSelected(stroke, true)
       }
   }
}
```

| Parameters |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch` | The `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch` to create a closed shape from. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh` | The `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh` of the closed shape. If there are fewer than 3 input points, or if there are fewer than 3 points remaining after removing points with the same (x,y) coordinates as the previous point, this function will return a `https://developer.android.com/reference/kotlin/androidx/ink/geometry/PartitionedMesh` that is point-like (1 point remaining) or segment-like (2 points remaining). The resulting mesh will have an area of 0 but can still be used for hit testing via intersection. |

### StrokeInputBatch.encode

Cmn Artifact: [androidx.ink:ink-storage](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/storage/StrokeInputBatchExtensions.kt+function:encode)

```
fun StrokeInputBatch.encode(): ByteArray
```

Write a gzip-compressed `ink.proto.CodedStrokeInputBatch` binary proto message representing the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch` to the given `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html`.

### StrokeInputBatch.encode

android Artifact: [androidx.ink:ink-storage](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/storage/StrokeInputBatchExtensions.jvmAndAndroid.kt+function:encode)

```
fun StrokeInputBatch.encode(output: OutputStream): Unit
```

Write a gzip-compressed `ink.proto.CodedStrokeInputBatch` binary proto message representing the `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokeInputBatch` to the given `https://developer.android.com/reference/java/io/OutputStream.html`.