VelocityTracker

class VelocityTracker
kotlin.Any
   ↳ androidx.ui.core.gesture.util.VelocityTracker

Computes a pointer's velocity.

The input data is provided by calling addPosition. Adding data is cheap.

To obtain a velocity, call calculateVelocity or getVelocityEstimate. This will compute the velocity based on the data added so far. Only call these when you need to use the velocity, as they are comparatively expensive.

The quality of the velocity estimation will be better if more data points have been received.

Summary

Public constructors

Computes a pointer's velocity.

Public methods

Unit
addPosition(time: Timestamp, position: PxPosition)

Adds a position as the given time to the tracker.

Velocity

Computes the estimated velocity of the pointer at the time of the last provided data point.

Unit

Clears the tracked positions added by addPosition.

Public constructors

<init>

VelocityTracker()

Computes a pointer's velocity.

The input data is provided by calling addPosition. Adding data is cheap.

To obtain a velocity, call calculateVelocity or getVelocityEstimate. This will compute the velocity based on the data added so far. Only call these when you need to use the velocity, as they are comparatively expensive.

The quality of the velocity estimation will be better if more data points have been received.

Public methods

addPosition

fun addPosition(
    time: Timestamp,
    position: PxPosition
): Unit

Adds a position as the given time to the tracker.

Call resetTracking to remove added Offsets.

See Also

calculateVelocity

fun calculateVelocity(): Velocity

Computes the estimated velocity of the pointer at the time of the last provided data point.

This can be expensive. Only call this when you need the velocity.

resetTracking

fun resetTracking(): Unit

Clears the tracked positions added by addPosition.