mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-15 12:45:01 +00:00
fix: Catching case where MapRange would generate a NaN value
This commit is contained in:
@@ -71,6 +71,9 @@ namespace ICD.Common.Utils
|
|||||||
/// <returns>The newly mapped value</returns>
|
/// <returns>The newly mapped value</returns>
|
||||||
public static double MapRange(double inputStart, double inputEnd, double outputStart, double outputEnd, double value)
|
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);
|
double slope = (outputEnd - outputStart) / (inputEnd - inputStart);
|
||||||
return outputStart + slope * (value - inputStart);
|
return outputStart + slope * (value - inputStart);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user