StrokeInputBatch


abstract class StrokeInputBatch

Known direct subclasses
ImmutableStrokeInputBatch

An immutable implementation of StrokeInputBatch.

MutableStrokeInputBatch

A mutable implementation of StrokeInputBatch.


A read-only view of an object that stores multiple 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 toolType and the same set of optional fields like pressure/tilt/orientation, and their timestamps are all monotonically non-decreasing. This can be an ImmutableStrokeInputBatch for data that cannot change, and a MutableStrokeInputBatch for data that is meant to be modified or incrementally built.

Summary

Nested types

Public functions

operator StrokeInput
get(index: Int)

Gets the value of the i-th input.

Long

The duration between the first and last input in milliseconds.

Float

The physical distance in centimeters that the pointer must travel in order to produce an input motion of one stroke unit.

InputToolType

How this input stream should be interpreted, as coming from a InputToolType.MOUSE, InputToolType.TOUCH, or InputToolType.STYLUS.

Boolean

Whether all of the individual inputs have a defined value for StrokeInput.orientationRadians.

Boolean

Whether all of the individual inputs have a defined value for StrokeInput.pressure.

Boolean

Whether strokeUnitLengthCm has a valid value, which is something other than StrokeInput.NO_STROKE_UNIT_LENGTH.

Boolean

Whether all of the individual inputs have a defined value for StrokeInput.tiltRadians.

Boolean

true if there are no StrokeInput objects in the batch, and false otherwise.

StrokeInput
populate(index: Int, outStrokeInput: StrokeInput)

Gets the value of the i-th input and overwrites outStrokeInput, which it then returns.

Protected functions

Unit

Public properties

Int

Number of StrokeInput objects in the batch.

Extension functions

PartitionedMesh

Creates a PartitionedMesh of the shape enclosed by the given StrokeInputBatch input points.

Unit

Write the gzip-compressed serialized representation of the CodedStrokeInputBatch to the given OutputStream.

Public functions

get

Added in 1.0.0-alpha03
operator fun get(index: Int): StrokeInput

Gets the value of the i-th input. Requires that index is positive and less than size.

In performance-sensitive code, prefer to use populate to pass in a pre-allocated instance and reuse that instance across multiple calls to this function.

getDurationMillis

Added in 1.0.0-alpha03
fun getDurationMillis(): Long

The duration between the first and last input in milliseconds.

getStrokeUnitLengthCm

Added in 1.0.0-alpha03
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 StrokeInput.NO_STROKE_UNIT_LENGTH indicates that the relationship between stroke space and physical space is unknown or ill-defined.

getToolType

Added in 1.0.0-alpha03
fun getToolType(): InputToolType

How this input stream should be interpreted, as coming from a InputToolType.MOUSE, InputToolType.TOUCH, or InputToolType.STYLUS.

hasOrientation

Added in 1.0.0-alpha03
fun hasOrientation(): Boolean

Whether all of the individual inputs have a defined value for StrokeInput.orientationRadians. If not, then no input items have an orientation value.

hasPressure

Added in 1.0.0-alpha03
fun hasPressure(): Boolean

Whether all of the individual inputs have a defined value for StrokeInput.pressure. If not, then no input items have a pressure value.

hasStrokeUnitLength

Added in 1.0.0-alpha03
fun hasStrokeUnitLength(): Boolean

Whether strokeUnitLengthCm has a valid value, which is something other than StrokeInput.NO_STROKE_UNIT_LENGTH.

hasTilt

Added in 1.0.0-alpha03
fun hasTilt(): Boolean

Whether all of the individual inputs have a defined value for StrokeInput.tiltRadians. If not, then no input items have a tilt value.

isEmpty

Added in 1.0.0-alpha03
fun isEmpty(): Boolean

true if there are no StrokeInput objects in the batch, and false otherwise.

populate

Added in 1.0.0-alpha03
fun populate(index: Int, outStrokeInput: StrokeInput): StrokeInput

Gets the value of the i-th input and overwrites outStrokeInput, which it then returns. Requires that index is positive and less than size.

Protected functions

finalize

Added in 1.0.0-alpha03
protected fun finalize(): Unit

Public properties

size

Added in 1.0.0-alpha03
val sizeInt

Number of StrokeInput objects in the batch.

Extension functions

createClosedShape

fun StrokeInputBatch.createClosedShape(): PartitionedMesh

Creates a PartitionedMesh of the shape enclosed by the given StrokeInputBatch input points. A typical use case is selecting a region of the scene and performing hit testing with the resulting 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:

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

The StrokeInputBatch to create a closed shape from.

Returns
PartitionedMesh

The 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 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.

fun StrokeInputBatch.encode(output: OutputStream): Unit

Write the gzip-compressed serialized representation of the CodedStrokeInputBatch to the given OutputStream.