From 3a6b73e637007b9c289b1a9f236aeb76dfa68240 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 14 Mar 2023 14:42:13 -0700 Subject: [PATCH] add int clamp to MathHelper --- src/Math/MathHelper.cs | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/Math/MathHelper.cs b/src/Math/MathHelper.cs index e7f7a56..a4477a2 100644 --- a/src/Math/MathHelper.cs +++ b/src/Math/MathHelper.cs @@ -160,6 +160,26 @@ namespace MoonWorks.Math return value; } + /// + /// Restricts a value to be within a specified range. + /// + /// The value to clamp. + /// + /// The minimum value. If value is less than min, min + /// will be returned. + /// + /// + /// The maximum value. If value is greater than max, max + /// will be returned. + /// + /// The clamped value. + public static int Clamp(int value, int min, int max) + { + value = (value > max) ? max : value; + value = (value < min) ? min : value; + return value; + } + /// /// Calculates the absolute value of the difference of two values. /// @@ -400,27 +420,6 @@ namespace MoonWorks.Math #region Internal Static Methods - // FIXME: This could be an extension! ClampIntEXT? -flibit - /// - /// Restricts a value to be within a specified range. - /// - /// The value to clamp. - /// - /// The minimum value. If value is less than min, min - /// will be returned. - /// - /// - /// The maximum value. If value is greater than max, max - /// will be returned. - /// - /// The clamped value. - internal static int Clamp(int value, int min, int max) - { - value = (value > max) ? max : value; - value = (value < min) ? min : value; - return value; - } - internal static bool WithinEpsilon(float floatA, float floatB) { return System.Math.Abs(floatA - floatB) < MachineEpsilonFloat;