fix: Catching case where MapRange would generate a NaN value

This commit is contained in:
Chris Cameron
2018-04-05 09:31:11 -04:00
parent a24b32332a
commit e6d11bd3fa

View File

@@ -71,6 +71,9 @@ namespace ICD.Common.Utils
/// <returns>The newly mapped value</returns>
public static double MapRange(double inputStart, double inputEnd, double outputStart, double outputEnd, double value)
{
if (inputStart.Equals(inputEnd))
throw new DivideByZeroException();
double slope = (outputEnd - outputStart) / (inputEnd - inputStart);
return outputStart + slope * (value - inputStart);
}