diff options
author | Peter Hutterer <peter.hutterer@redhat.com> | 2008-10-02 08:55:14 +0930 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@redhat.com> | 2008-10-03 15:27:07 +0930 |
commit | 9c8a2be2c73abf06245b1eb7f05f93e104dcfe42 (patch) | |
tree | 8a9f7f9bf3c40f0818439ef7d367206c13ffc071 /dix | |
parent | 93ef72fa26b27cf90bf5c64ec19ac295a113aaae (diff) |
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.
Diffstat (limited to 'dix')
-rw-r--r-- | dix/getevents.c | 8 |
1 files 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; } /** |