Skip to content

Instantly share code, notes, and snippets.

@danieldownes
Created March 11, 2022 13:01
Show Gist options
  • Save danieldownes/602cadc83a824e79bfc4587b23e37699 to your computer and use it in GitHub Desktop.
Save danieldownes/602cadc83a824e79bfc4587b23e37699 to your computer and use it in GitHub Desktop.
ConvertRange oldValue, oldMin, oldMax, newMin, newMax
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