Created
March 11, 2022 13:01
-
-
Save danieldownes/602cadc83a824e79bfc4587b23e37699 to your computer and use it in GitHub Desktop.
ConvertRange oldValue, oldMin, oldMax, newMin, newMax
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
public static float ConvertRange(float oldValue, float oldMin, float oldMax, float newMin = 0, float newMax = 1) | |
{ | |
float oldRange = (oldMax - oldMin); | |
if (oldRange == 0) | |
return newMin; | |
else | |
return (((oldValue - oldMin) * (newMax - newMin)) / oldRange) + newMin; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment