From 09cdb98dfceb97f5810a76e17c5bc12d1c7e7a87 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Sun, 15 Mar 2026 17:38:23 -0400 Subject: [PATCH] refactor: extract Rounding from Helper to OpenNest.Math Co-Authored-By: Claude Opus 4.6 (1M context) --- OpenNest.Core/Helper.cs | 33 ---------------------------- OpenNest.Core/Math/Rounding.cs | 40 ++++++++++++++++++++++++++++++++++ OpenNest.Core/Plate.cs | 4 ++-- 3 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 OpenNest.Core/Math/Rounding.cs diff --git a/OpenNest.Core/Helper.cs b/OpenNest.Core/Helper.cs index 44aa015..60c3ed6 100644 --- a/OpenNest.Core/Helper.cs +++ b/OpenNest.Core/Helper.cs @@ -11,39 +11,6 @@ namespace OpenNest { public static class Helper { - /// - /// 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; - } - public static void Optimize(IList arcs) { for (int i = 0; i < arcs.Count; ++i) diff --git a/OpenNest.Core/Math/Rounding.cs b/OpenNest.Core/Math/Rounding.cs new file mode 100644 index 0000000..28892b2 --- /dev/null +++ b/OpenNest.Core/Math/Rounding.cs @@ -0,0 +1,40 @@ +using OpenNest.Math; + +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; + } + } +} diff --git a/OpenNest.Core/Plate.cs b/OpenNest.Core/Plate.cs index 4bc49b7..5005529 100644 --- a/OpenNest.Core/Plate.cs +++ b/OpenNest.Core/Plate.cs @@ -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)); } ///