From e6d11bd3fae1b46247a7f08545e8a6b63d3a24d8 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 5 Apr 2018 09:31:11 -0400 Subject: [PATCH] fix: Catching case where MapRange would generate a NaN value --- ICD.Common.Utils/MathUtils.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ICD.Common.Utils/MathUtils.cs b/ICD.Common.Utils/MathUtils.cs index 26b9258..7d718fd 100644 --- a/ICD.Common.Utils/MathUtils.cs +++ b/ICD.Common.Utils/MathUtils.cs @@ -71,6 +71,9 @@ namespace ICD.Common.Utils /// The newly mapped 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); return outputStart + slope * (value - inputStart); }