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