From 5f123a1dbbc22383f86d51aaea1387b8ec292c94 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Mar 2015 11:33:55 +1000 Subject: [PATCH] filter: calculate the time delta correctly If the delta is 0, the distance is the number of units (within this ms). Delta 1 means velocity across 2 ms, etc. Bonus: this doesn't return infinite speed anymore if we get more than one event per ms. This can happen on any device approaching 1000Hz poll rate, but definitely got triggered by the test suite. Actual effect was limited, since we cap out acceleration at max_accel we just hit this earlier and it stayed there. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/filter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/filter.c b/src/filter.c index 7e935bff..dc299286 100644 --- a/src/filter.c +++ b/src/filter.c @@ -138,9 +138,10 @@ static double calculate_tracker_velocity(struct pointer_tracker *tracker, uint64_t time) { double distance; + double tdelta = time - tracker->time + 1; distance = hypot(tracker->delta.x, tracker->delta.y); - return distance / (double)(time - tracker->time); /* units/ms */ + return distance / tdelta; /* units/ms */ } static double