1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-09 23:25:43 +00:00

Inline Lerp/InverseLerp expression in ScaleRange

This commit is contained in:
Oliver Booth 2023-02-26 13:26:08 +00:00
parent 795d696eca
commit 81f1a7c1e0
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025

View File

@ -246,8 +246,10 @@ public static class MathUtility
/// <returns>The scaled value.</returns>
public static float ScaleRange(float value, float oldMin, float oldMax, float newMin, float newMax)
{
float alpha = InverseLerp(value, oldMin, oldMax);
return Lerp(newMin, newMax, alpha);
float oldRange = oldMax - oldMin;
float newRange = newMax - newMin;
float alpha = (value - oldMin) / oldRange;
return (alpha * newRange) + newMin;
}
/// <summary>
@ -261,7 +263,9 @@ public static class MathUtility
/// <returns>The scaled value.</returns>
public static double ScaleRange(double value, double oldMin, double oldMax, double newMin, double newMax)
{
double alpha = InverseLerp(value, oldMin, oldMax);
return Lerp(newMin, newMax, alpha);
double oldRange = oldMax - oldMin;
double newRange = newMax - newMin;
double alpha = (value - oldMin) / oldRange;
return (alpha * newRange) + newMin;
}
}