mirror of
https://github.com/X11Libre/xserver.git
synced 2026-03-25 19:19:13 +00:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user