Created
January 31, 2019 13:59
-
-
Save anechunaev/4c8a8fdd66f615e4d7f0c23f6ee53851 to your computer and use it in GitHub Desktop.
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
function linearToLogarithmic(linearValue: number, minValue: number, maxValue: number) { | |
const range = maxValue - minValue; | |
let value = Math.round(Math.pow(range + 1, linearValue) + minValue - 1); | |
if (value < minValue) { | |
value = minValue; | |
} else if (value > maxValue) { | |
value = maxValue; | |
} | |
return value; | |
}; | |
function logarithmicToLinear(scale: number, minValue: number, maxValue: number) { | |
const range = maxValue - minValue; | |
const normalizedValue = scale - minValue + 1; | |
if (normalizedValue <= 0) { | |
return 0; | |
} else if (scale >= maxValue) { | |
return 1; | |
} else { | |
return Math.log(normalizedValue) / Math.log(range + 1); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment