using System; using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; namespace PepperDash.Essentials.Core { public class NumericalHelpers { /// /// Scales a value /// /// /// /// /// /// /// public static double Scale(double input, double inMin, double inMax, double outMin, double outMax) { //Debug.Console(2, this, "Scaling (double) input '{0}' with min '{1}'/max '{2}' to output range min '{3}'/max '{4}'", input, inMin, inMax, outMin, outMax); double inputRange = inMax - inMin; if (inputRange <= 0) { throw new ArithmeticException(string.Format("Invalid Input Range '{0}' for Scaling. Min '{1}' Max '{2}'.", inputRange, inMin, inMax)); } double outputRange = outMax - outMin; var output = (((input - inMin) * outputRange) / inputRange) + outMin; // Debug.Console(2, this, "Scaled output '{0}'", output); return output; } } }