Added Utils class.

This commit is contained in:
Zdenek Borovec 2024-03-02 11:23:42 +01:00
parent c6675bb051
commit 79fe8638af

28
utils/Utils.cs Normal file
View file

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GeometriCS
{
/// <summary>
/// Common utilities throughout the library.
/// </summary>
internal static class Utils
{
/// <summary>
/// Default precision for double equality comparison.
/// </summary>
private const double DOUBLEPRECISION = 1E-5;
/// <summary>
/// Tests whether the difference between two doubles is within a given limit.
/// </summary>
/// <param name="a">First value to test.</param>
/// <param name="b">Second value to test.</param>
/// <param name="prec">Maximum allowed difference.</param>
/// <returns>Do the values almost equal each other.</returns>
public static bool DoubleEquals(double a, double b, double prec = DOUBLEPRECISION) => Math.Abs(a - b) <= prec;
}
}