mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-23 05:01:12 +00:00
[Math] Added MathHelper.Clamp
This commit is contained in:
parent
a9ab3650da
commit
88c57db5b6
|
@ -288,6 +288,46 @@ namespace OpenTK
|
|||
|
||||
#endregion
|
||||
|
||||
#region Clamp
|
||||
|
||||
/// <summary>
|
||||
/// Clamps a number between a minimum and a maximum.
|
||||
/// </summary>
|
||||
/// <param name="n">The number to clamp.</param>
|
||||
/// <param name="min">The minimum allowed value.</param>
|
||||
/// <param name="max">The maximum allowed value.</param>
|
||||
/// <returns>min, if n is lower than min; max, if n is higher than max; n otherwise.</returns>
|
||||
public static int Clamp(int n, int min, int max)
|
||||
{
|
||||
return Math.Max(Math.Min(n, max), min);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamps a number between a minimum and a maximum.
|
||||
/// </summary>
|
||||
/// <param name="n">The number to clamp.</param>
|
||||
/// <param name="min">The minimum allowed value.</param>
|
||||
/// <param name="max">The maximum allowed value.</param>
|
||||
/// <returns>min, if n is lower than min; max, if n is higher than max; n otherwise.</returns>
|
||||
public static float Clamp(float n, float min, float max)
|
||||
{
|
||||
return Math.Max(Math.Min(n, max), min);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clamps a number between a minimum and a maximum.
|
||||
/// </summary>
|
||||
/// <param name="n">The number to clamp.</param>
|
||||
/// <param name="min">The minimum allowed value.</param>
|
||||
/// <param name="max">The maximum allowed value.</param>
|
||||
/// <returns>min, if n is lower than min; max, if n is higher than max; n otherwise.</returns>
|
||||
public static double Clamp(double n, double min, double max)
|
||||
{
|
||||
return Math.Max(Math.Min(n, max), min);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue