refactor: extract Rounding from Helper to OpenNest.Math
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -11,39 +11,6 @@ namespace OpenNest
|
||||
{
|
||||
public static class Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// Rounds a number down to the nearest factor.
|
||||
/// </summary>
|
||||
/// <param name="num"></param>
|
||||
/// <param name="factor"></param>
|
||||
/// <returns></returns>
|
||||
public static double RoundDownToNearest(double num, double factor)
|
||||
{
|
||||
return factor.IsEqualTo(0) ? num : System.Math.Floor(num / factor) * factor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds a number up to the nearest factor.
|
||||
/// </summary>
|
||||
/// <param name="num"></param>
|
||||
/// <param name="factor"></param>
|
||||
/// <returns></returns>
|
||||
public static double RoundUpToNearest(double num, double factor)
|
||||
{
|
||||
return factor.IsEqualTo(0) ? num : System.Math.Ceiling(num / factor) * factor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds a number to the nearest factor using midpoint rounding convention.
|
||||
/// </summary>
|
||||
/// <param name="num"></param>
|
||||
/// <param name="factor"></param>
|
||||
/// <returns></returns>
|
||||
public static double RoundToNearest(double num, double factor)
|
||||
{
|
||||
return factor.IsEqualTo(0) ? num : System.Math.Round(num / factor) * factor;
|
||||
}
|
||||
|
||||
public static void Optimize(IList<Arc> arcs)
|
||||
{
|
||||
for (int i = 0; i < arcs.Count; ++i)
|
||||
|
||||
40
OpenNest.Core/Math/Rounding.cs
Normal file
40
OpenNest.Core/Math/Rounding.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using OpenNest.Math;
|
||||
|
||||
namespace OpenNest.Math
|
||||
{
|
||||
public static class Rounding
|
||||
{
|
||||
/// <summary>
|
||||
/// Rounds a number down to the nearest factor.
|
||||
/// </summary>
|
||||
/// <param name="num"></param>
|
||||
/// <param name="factor"></param>
|
||||
/// <returns></returns>
|
||||
public static double RoundDownToNearest(double num, double factor)
|
||||
{
|
||||
return factor.IsEqualTo(0) ? num : System.Math.Floor(num / factor) * factor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds a number up to the nearest factor.
|
||||
/// </summary>
|
||||
/// <param name="num"></param>
|
||||
/// <param name="factor"></param>
|
||||
/// <returns></returns>
|
||||
public static double RoundUpToNearest(double num, double factor)
|
||||
{
|
||||
return factor.IsEqualTo(0) ? num : System.Math.Ceiling(num / factor) * factor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rounds a number to the nearest factor using midpoint rounding convention.
|
||||
/// </summary>
|
||||
/// <param name="num"></param>
|
||||
/// <param name="factor"></param>
|
||||
/// <returns></returns>
|
||||
public static double RoundToNearest(double num, double factor)
|
||||
{
|
||||
return factor.IsEqualTo(0) ? num : System.Math.Round(num / factor) * factor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -412,8 +412,8 @@ namespace OpenNest
|
||||
}
|
||||
|
||||
Size = new Size(
|
||||
Helper.RoundUpToNearest(width, roundingFactor),
|
||||
Helper.RoundUpToNearest(length, roundingFactor));
|
||||
Rounding.RoundUpToNearest(width, roundingFactor),
|
||||
Rounding.RoundUpToNearest(length, roundingFactor));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user