We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The current (as of 2016-09-29) implementation of Math.scale does not work if the output scale is "negative"
Math.scale
Math.scale(0.6, 0,1, 0,10); // <= should return 6 [0...1] => [0...10] Math.scale(0.6, 0,1, 10,0); // <= should return 4 [0...1] => [10...0] Math.scale(0.6, 0,1, 0,-10); // <= should return -6 [0...1] => [0...-10]
I also think this "flipping of scales" should maybe mentioned specifically in the reference / manual
A working polyfill seems to be this:
defineMath("scale", function scale(value, inMin, inMax, outMin, outMax) { if ( arguments.length === 0 || Number.isNaN(value) || Number.isNaN(inMin) || Number.isNaN(inMax) || Number.isNaN(outMin) || Number.isNaN(outMax) ) { return NaN; } if ( value === Infinity || value === -Infinity || (inMin == outMin && inMax == outMax) ) { return value; } return outMin + ((value - inMin) / (inMax - inMin)) * (outMax - outMin); });
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The current (as of 2016-09-29) implementation of
Math.scale
does not work if the output scale is "negative"I also think this "flipping of scales" should maybe mentioned specifically in the reference / manual
A working polyfill seems to be this:
The text was updated successfully, but these errors were encountered: