From 3022982f6dcbbccf55285ee9f7227e5c7c401a2d Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Sat, 28 Mar 2026 16:22:00 -0400 Subject: [PATCH] refactor: consolidate HasOverlappingParts into FillHelpers StripeFiller and FillExtents had identical 24-line overlap detection methods; move to FillHelpers and delegate from both callers. Co-Authored-By: Claude Opus 4.6 (1M context) --- OpenNest.Engine/Fill/FillExtents.cs | 28 +++----------------- OpenNest.Engine/Fill/StripeFiller.cs | 31 ++--------------------- OpenNest.Engine/Strategies/FillHelpers.cs | 30 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 54 deletions(-) diff --git a/OpenNest.Engine/Fill/FillExtents.cs b/OpenNest.Engine/Fill/FillExtents.cs index 76380b4..0c09a77 100644 --- a/OpenNest.Engine/Fill/FillExtents.cs +++ b/OpenNest.Engine/Fill/FillExtents.cs @@ -1,3 +1,4 @@ +using OpenNest.Engine.Strategies; using OpenNest.Geometry; using OpenNest.Math; using System; @@ -411,30 +412,7 @@ namespace OpenNest.Engine.Fill part.BoundingBox.Bottom >= workArea.Bottom - Tolerance.Epsilon; } - private static bool HasOverlappingParts(List parts) - { - for (var i = 0; i < parts.Count; i++) - { - var b1 = parts[i].BoundingBox; - - for (var j = i + 1; j < parts.Count; j++) - { - var b2 = parts[j].BoundingBox; - - var overlapX = System.Math.Min(b1.Right, b2.Right) - - System.Math.Max(b1.Left, b2.Left); - var overlapY = System.Math.Min(b1.Top, b2.Top) - - System.Math.Max(b1.Bottom, b2.Bottom); - - if (overlapX <= Tolerance.Epsilon || overlapY <= Tolerance.Epsilon) - continue; - - if (parts[i].Intersects(parts[j], out _)) - return true; - } - } - - return false; - } + private static bool HasOverlappingParts(List parts) => + FillHelpers.HasOverlappingParts(parts); } } diff --git a/OpenNest.Engine/Fill/StripeFiller.cs b/OpenNest.Engine/Fill/StripeFiller.cs index f8eb126..f882b02 100644 --- a/OpenNest.Engine/Fill/StripeFiller.cs +++ b/OpenNest.Engine/Fill/StripeFiller.cs @@ -481,33 +481,6 @@ public class StripeFiller return axis == NestDirection.Horizontal ? box.Width : box.Length; } - /// - /// Checks if any pair of parts geometrically overlap. Uses bounding box - /// pre-filtering for performance, then falls back to shape intersection. - /// - private static bool HasOverlappingParts(List parts) - { - for (var i = 0; i < parts.Count; i++) - { - var b1 = parts[i].BoundingBox; - - for (var j = i + 1; j < parts.Count; j++) - { - var b2 = parts[j].BoundingBox; - - var overlapX = System.Math.Min(b1.Right, b2.Right) - - System.Math.Max(b1.Left, b2.Left); - var overlapY = System.Math.Min(b1.Top, b2.Top) - - System.Math.Max(b1.Bottom, b2.Bottom); - - if (overlapX <= Tolerance.Epsilon || overlapY <= Tolerance.Epsilon) - continue; - - if (parts[i].Intersects(parts[j], out _)) - return true; - } - } - - return false; - } + private static bool HasOverlappingParts(List parts) => + FillHelpers.HasOverlappingParts(parts); } diff --git a/OpenNest.Engine/Strategies/FillHelpers.cs b/OpenNest.Engine/Strategies/FillHelpers.cs index a2873e0..db541b9 100644 --- a/OpenNest.Engine/Strategies/FillHelpers.cs +++ b/OpenNest.Engine/Strategies/FillHelpers.cs @@ -109,5 +109,35 @@ namespace OpenNest.Engine.Strategies var fallback = fillFunc(other); return fallback ?? new List(); } + + /// + /// Checks if any pair of parts geometrically overlap. Uses bounding box + /// pre-filtering for performance, then falls back to shape intersection. + /// + internal static bool HasOverlappingParts(List parts) + { + for (var i = 0; i < parts.Count; i++) + { + var b1 = parts[i].BoundingBox; + + for (var j = i + 1; j < parts.Count; j++) + { + var b2 = parts[j].BoundingBox; + + var overlapX = System.Math.Min(b1.Right, b2.Right) + - System.Math.Max(b1.Left, b2.Left); + var overlapY = System.Math.Min(b1.Top, b2.Top) + - System.Math.Max(b1.Bottom, b2.Bottom); + + if (overlapX <= Tolerance.Epsilon || overlapY <= Tolerance.Epsilon) + continue; + + if (parts[i].Intersects(parts[j], out _)) + return true; + } + } + + return false; + } } }