From 9c8a2be2c73abf06245b1eb7f05f93e104dcfe42 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 2 Oct 2008 08:55:14 +0930 Subject: [PATCH] dix: fix axis scaling. For two axes [a, b] and [x, y] (inclusive), the formula to scale point P(ab) to (x,y) is: (P - a)/(b - a) * (y - x) + x And the whole end result rounded of course to get the integer we need. --- dix/getevents.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dix/getevents.c b/dix/getevents.c index f2086e8d6..ed7bf7ffa 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -175,8 +175,12 @@ rescaleValuatorAxis(int coord, AxisInfoPtr from, AxisInfoPtr to, if(fmin == tmin && fmax == tmax) return coord; - return (int)(((float)(coord - fmin)) * (tmax - tmin + 1) / - (fmax - fmin + 1)) + tmin; + + if(fmax == fmin) /* avoid division by 0 */ + return 0; + + return roundf(((float)(coord - fmin)) * (tmax - tmin) / + (fmax - fmin)) + tmin; } /**