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 <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
Peter Hutterer 2015-03-19 11:10:37 +10:00
parent 69d5bbbeba
commit cea13bb494

View file

@ -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)