From cea13bb4948548a290eba7eafa562f9cc723a10d Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 19 Mar 2015 11:10:37 +1000 Subject: [PATCH] Switch vector_get_direction to use doubles Delta movements on most slower movements are less than 1.0 per event, so we'd end up with an undefined direction for all of them. This led to the velocity being calculated across opposite movements rather than (as intended) across movements within a shared octant. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- src/libinput-util.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libinput-util.h b/src/libinput-util.h index bd71a1ff..91918235 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -111,28 +111,28 @@ enum directions { }; static inline int -vector_get_direction(int dx, int dy) +vector_get_direction(double dx, double dy) { int dir = UNDEFINED_DIRECTION; int d1, d2; double r; - if (abs(dx) < 2 && abs(dy) < 2) { - if (dx > 0 && dy > 0) + if (fabs(dx) < 2.0 && fabs(dy) < 2.0) { + if (dx > 0.0 && dy > 0.0) dir = S | SE | E; - else if (dx > 0 && dy < 0) + else if (dx > 0.0 && dy < 0.0) dir = N | NE | E; - else if (dx < 0 && dy > 0) + else if (dx < 0.0 && dy > 0.0) dir = S | SW | W; - else if (dx < 0 && dy < 0) + else if (dx < 0.0 && dy < 0.0) dir = N | NW | W; - else if (dx > 0) + else if (dx > 0.0) dir = NE | E | SE; - else if (dx < 0) + else if (dx < 0.0) dir = NW | W | SW; - else if (dy > 0) + else if (dy > 0.0) dir = SE | S | SW; - else if (dy < 0) + else if (dy < 0.0) dir = NE | N | NW; } else { /* Calculate r within the interval [0 to 8)