VelocityTracker
class VelocityTracker
kotlin.Any | |
↳ | androidx.compose.ui.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 | |
---|---|
<init>() Computes a pointer's velocity. |
Public methods | |
---|---|
Unit |
addPosition(uptime: Uptime, position: Offset) 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(
uptime: Uptime,
position: Offset
): 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.