namespace OpenNest.Math
{
public static class Rounding
{
///
/// Rounds a number down to the nearest factor.
///
///
///
///
public static double RoundDownToNearest(double num, double factor)
{
return factor.IsEqualTo(0) ? num : System.Math.Floor(num / factor) * factor;
}
///
/// Rounds a number up to the nearest factor.
///
///
///
///
public static double RoundUpToNearest(double num, double factor)
{
return factor.IsEqualTo(0) ? num : System.Math.Ceiling(num / factor) * factor;
}
///
/// Rounds a number to the nearest factor using midpoint rounding convention.
///
///
///
///
public static double RoundToNearest(double num, double factor)
{
return factor.IsEqualTo(0) ? num : System.Math.Round(num / factor) * factor;
}
}
}