ReleaseVelocitySampler

class ReleaseVelocitySampler(capacity: Int = 5, windowMs: Double = 100.0)

Samples a drag's instantaneous velocity into a small ring buffer and, on release, computes the average velocity over the last windowMs of motion. Better than EMA for fling: users tend to decelerate slightly just before lifting, and the EMA smears that deceleration into the reported release velocity. Averaging over a short trailing window captures the actual flick speed.

Units of dx/dy/dt are caller-defined — typically (pixels, pixels, milliseconds), giving a release velocity in pixels per millisecond.

Constructors

Link copied to clipboard
constructor(capacity: Int = 5, windowMs: Double = 100.0)

Functions

Link copied to clipboard

Returns the average (vx, vy) over samples covering up to windowMs of motion ending at the most recent record. Walks newest-to-oldest; stops as soon as the accumulated dt reaches windowMs. Returns (0.0, 0.0) if no samples have been recorded.

Link copied to clipboard
fun record(deltaPxX: Double, deltaPxY: Double, dtMs: Double)

Records one motion segment. Zero or negative dtMs is silently ignored.

Link copied to clipboard
fun reset()

Discards all samples — call when a new gesture begins.