StrokeInputBatch
public abstract class StrokeInputBatch
ImmutableStrokeInputBatch |
An immutable implementation of |
MutableStrokeInputBatch |
A mutable implementation of |
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 static class StrokeInputBatch.Companion |
Public methods |
|
|---|---|
final @NonNull StrokeInput |
get(int index)Gets the value of the i-th input. |
final long |
The duration between the first and last input in milliseconds. |
final 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. |
final int |
getSize()Number of |
final float |
The physical distance in centimeters that the pointer must travel in order to produce an input motion of one stroke unit. |
final @NonNull InputToolType |
How this input stream should be interpreted, as coming from a |
final boolean |
Whether all of the individual inputs have a defined value for |
final boolean |
Whether all of the individual inputs have a defined value for |
final boolean |
Whether strokeUnitLengthCm has a valid value, which is something other than |
final boolean |
hasTilt()Whether all of the individual inputs have a defined value for |
final boolean |
isEmpty()
|
final @NonNull StrokeInput |
populate(int index, @NonNull StrokeInput outStrokeInput)Gets the value of the i-th input and overwrites |
Protected methods |
|
|---|---|
final void |
finalize() |
Extension functions |
|
|---|---|
final @NonNull PartitionedMesh |
MeshCreation.createClosedShape(@NonNull StrokeInputBatch receiver)Creates a |
final void |
StrokeInputBatchExtensions.encode(Write a gzip-compressed |
Public methods
get
public final @NonNull StrokeInput get(int index)
Gets the value of the i-th input. Requires that index is non-negative 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
public final long getDurationMillis()
The duration between the first and last input in milliseconds.
getNoiseSeed
@ExperimentalInkCustomBrushApi
public final int 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. If no seed value has yet been set for this input batch, returns the default seed of zero.
getStrokeUnitLengthCm
public final float getStrokeUnitLengthCm()
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
public final @NonNull InputToolType getToolType()
How this input stream should be interpreted, as coming from a InputToolType.MOUSE, InputToolType.TOUCH, or InputToolType.STYLUS.
hasOrientation
public final boolean hasOrientation()
Whether all of the individual inputs have a defined value for StrokeInput.orientationRadians. If not, then no input items have an orientation value.
hasPressure
public final boolean hasPressure()
Whether all of the individual inputs have a defined value for StrokeInput.pressure. If not, then no input items have a pressure value.
hasStrokeUnitLength
public final boolean hasStrokeUnitLength()
Whether strokeUnitLengthCm has a valid value, which is something other than StrokeInput.NO_STROKE_UNIT_LENGTH.
hasTilt
public final boolean hasTilt()
Whether all of the individual inputs have a defined value for StrokeInput.tiltRadians. If not, then no input items have a tilt value.
isEmpty
public final boolean isEmpty()
true if there are no StrokeInput objects in the batch, and false otherwise.
populate
public final @NonNull StrokeInput populate(int index, @NonNull StrokeInput outStrokeInput)
Gets the value of the i-th input and overwrites outStrokeInput, which it then returns. Requires that index is non-negative and less than size.
Protected methods
Extension functions
MeshCreation.createClosedShape
public final @NonNull PartitionedMesh MeshCreation.createClosedShape(@NonNull StrokeInputBatch receiver)
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:
-
Identify and create any connections that the user may have intended to make but did not fully connect.
-
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 | |
|---|---|
@NonNull StrokeInputBatch receiver |
The |
| Returns | |
|---|---|
@NonNull PartitionedMesh |
The |
StrokeInputBatchExtensions.encode
public final void StrokeInputBatchExtensions.encode(
@NonNull StrokeInputBatch receiver,
@NonNull OutputStream output
)
Write a gzip-compressed ink.proto.CodedStrokeInputBatch binary proto message representing the StrokeInputBatch to the given OutputStream.