Created
April 3, 2012 08:33
-
-
Save deciob/2290459 to your computer and use it in GitHub Desktop.
Linear scaling script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Scaler | |
scale: (range, domain) => | |
@rmax = domain[1] | |
@rmin = domain[0] | |
return (val) => | |
position_in = @getPositionInDomain(val) | |
position_out = @getPositionInRange(range, position_in) | |
Math.ceil(position_out) | |
getPositionInDomain: (val) => | |
abs_width = @rmax - @rmin | |
abs_val = @rmax - val | |
if abs_width == abs_val | |
return 100 | |
else | |
return 100 - (abs_val * 100 / abs_width) | |
getPositionInRange: (range, pir) => | |
abs_width = range[1] - range[0] | |
return range[0] + (abs_width * pir / 100) | |
scaler = new Scaler() | |
radius_range = @scaler.scale( | |
[6, 16], # range | |
[12, 456]) # domain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment