// Copyright (C) Stichting Deltares 2025. All rights reserved.
//
// This file is part of the Dam Engine.
//
// The Dam Engine is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
namespace Deltares.DamEngine.Data.Standard;
///
/// Static helper class ComputeDoubles with static helper methods
///
public static class ComputeDoubles
{
private const double cEpsilon = 1.0e-3;
///
/// Determines whether two values are nearly the same.
///
/// Uses a tolerance of 1e-3.
public static bool IsNearEqual(this double aValue1, double aValue2, double aTolerance = cEpsilon)
{
if (Math.Abs(aValue1 - aValue2) < aTolerance)
{
return true;
}
return false;
}
///
/// Determines whether the specified value is nearly equal to or is greater than
/// another value.
///
/// Uses a tolerance of 1e-3.
public static bool IsGreaterThanOrEqualTo(this double aValue1, double aValue2, double tolerance = cEpsilon)
{
if (aValue1 - aValue2 > -tolerance)
{
return true;
}
return false;
}
///
/// Determines whether a value is significantly less than another value.
///
/// Uses a tolerance of 1e-3.
public static bool IsLessThan(this double aValue1, double aValue2, double tolerance = cEpsilon)
{
return !IsGreaterThanOrEqualTo(aValue1, aValue2, tolerance);
}
///
/// Determines whether a value is insignificantly greater than, is equal to or is
/// less than another value.
///
/// Uses a tolerance of 1e-3.
public static bool IsLessThanOrEqualTo(this double aValue1, double aValue2, double tolerance = cEpsilon)
{
return !IsGreaterThan(aValue1, aValue2, tolerance);
}
///
/// Determines whether the specified value is nearly zero.
///
/// Uses a tolerance of 1e-3.
public static bool IsZero(this double aValue1)
{
if (Math.Abs(aValue1 - 0.0) < cEpsilon)
{
return true;
}
return false;
}
///
/// Determines whether the specified value is significantly greater than another value.
///
/// Uses a tolerance of 1e-3.
private static bool IsGreaterThan(this double aValue1, double aValue2, double tolerance = cEpsilon)
{
if (aValue1 - aValue2 > tolerance)
{
return true;
}
return false;
}
}