using System; namespace BOTWToolset { /// /// Extensions for Math. /// static class MathExt { /// /// Clamps a value into a minimum and maximum range. /// /// /// Value to clamp. /// The minimum value to use. /// The maximum value to use. /// public static T Clamp(this T val, T min, T max) where T : IComparable { if (val.CompareTo(min) < 0) return min; else if (val.CompareTo(max) > 0) return max; else return val; } /// /// Linearly interpolates a value. /// /// Value to interpolate. /// Value to interpolate to. /// Amount to interpolate - should be between 0 and 1. /// public static float Lerp(float from, float to, float delta) { if (delta > 1) return to; if (delta < 0) return from; return from + (to - from) * delta; } } }