forked from MoonsideGames/MoonWorks
add int clamp to MathHelper
parent
12e7e6b9c1
commit
3a6b73e637
|
@ -160,6 +160,26 @@ namespace MoonWorks.Math
|
|||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restricts a value to be within a specified range.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to clamp.</param>
|
||||
/// <param name="min">
|
||||
/// The minimum value. If <c>value</c> is less than <c>min</c>, <c>min</c>
|
||||
/// will be returned.
|
||||
/// </param>
|
||||
/// <param name="max">
|
||||
/// The maximum value. If <c>value</c> is greater than <c>max</c>, <c>max</c>
|
||||
/// will be returned.
|
||||
/// </param>
|
||||
/// <returns>The clamped value.</returns>
|
||||
public static int Clamp(int value, int min, int max)
|
||||
{
|
||||
value = (value > max) ? max : value;
|
||||
value = (value < min) ? min : value;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the absolute value of the difference of two values.
|
||||
/// </summary>
|
||||
|
@ -400,27 +420,6 @@ namespace MoonWorks.Math
|
|||
|
||||
#region Internal Static Methods
|
||||
|
||||
// FIXME: This could be an extension! ClampIntEXT? -flibit
|
||||
/// <summary>
|
||||
/// Restricts a value to be within a specified range.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to clamp.</param>
|
||||
/// <param name="min">
|
||||
/// The minimum value. If <c>value</c> is less than <c>min</c>, <c>min</c>
|
||||
/// will be returned.
|
||||
/// </param>
|
||||
/// <param name="max">
|
||||
/// The maximum value. If <c>value</c> is greater than <c>max</c>, <c>max</c>
|
||||
/// will be returned.
|
||||
/// </param>
|
||||
/// <returns>The clamped value.</returns>
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue