git-subtree-dir: LinearAlgebra git-subtree-mainline: 795e4730d0c8cb9859f26152f896e3ef2c88b4f2 git-subtree-split: 9b2a04746d3b7254f33b451a9e35597db305bd65
41 lines
1.2 KiB
C#
41 lines
1.2 KiB
C#
namespace LinearAlgebra {
|
|
|
|
/// <summary>
|
|
/// Float number utilities
|
|
/// </summary>
|
|
public class Float {
|
|
/// <summary>
|
|
/// The precision of float numbers
|
|
/// </summary>
|
|
public const float epsilon = 1E-05f;
|
|
/// <summary>
|
|
/// The square of the float number precision
|
|
/// </summary>
|
|
public const float sqrEpsilon = 1e-10f;
|
|
|
|
/// <summary>
|
|
/// Clamp the value between the given minimum and maximum values
|
|
/// </summary>
|
|
/// <param name="f">The value to clamp</param>
|
|
/// <param name="min">The minimum value</param>
|
|
/// <param name="max">The maximum value</param>
|
|
/// <returns>The clamped value</returns>
|
|
public static float Clamp(float f, float min, float max) {
|
|
if (f < min)
|
|
return min;
|
|
if (f > max)
|
|
return max;
|
|
return f;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clamp the value between to the interval [0..1]
|
|
/// </summary>
|
|
/// <param name="f">The value to clamp</param>
|
|
/// <returns>The clamped value</returns>
|
|
public static float Clamp01(float f) {
|
|
return Clamp(f, 0, 1);
|
|
}
|
|
}
|
|
|
|
} |