32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
using JD.Kernel.StaticHelpers;
|
|
|
|
namespace JD.Maths.Utils
|
|
{
|
|
public static class FloatExtension
|
|
{
|
|
public static bool Between(this float value, float lower, float upper)
|
|
{
|
|
Throw.InvalidArgumentIf(lower > upper, "lower is greater than upper", "lower");
|
|
|
|
return value >= lower && value <= upper;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if <paramref name="lhs"/> and <paramref name="rhs"/> are equals with <paramref name="epsilon"/>.
|
|
/// </summary>
|
|
public static bool EqualsWithEpsilon(this float lhs, float rhs, float epsilon)
|
|
{
|
|
Throw.InvalidArgumentIf(epsilon < 0f, "The epsilon must but equals or greater than zero.", "epsilon");
|
|
|
|
return System.Math.Abs(lhs - rhs) <= epsilon;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if <paramref name="lhs"/> and <paramref name="rhs"/> are equals with <see cref="Epsilon"/>.
|
|
/// </summary>
|
|
public static bool EqualsWithEpsilon(this float lhs, float rhs)
|
|
{
|
|
return EqualsWithEpsilon(lhs, rhs, MathConstants.Epsilon);
|
|
}
|
|
}
|
|
}
|