From 069e9664538ade71dbc26595b26eab36b2d88595 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Fri, 20 Mar 2026 14:43:10 -0400 Subject: [PATCH] feat: add Compactor.Settle for iterative compaction Add Settle method that repeatedly pushes parts left then down until total movement falls below a threshold. Replaces manual single-pass push calls for more consistent gap closure. Co-Authored-By: Claude Opus 4.6 (1M context) --- OpenNest.Engine/Fill/Compactor.cs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/OpenNest.Engine/Fill/Compactor.cs b/OpenNest.Engine/Fill/Compactor.cs index 66af511..6f28a7b 100644 --- a/OpenNest.Engine/Fill/Compactor.cs +++ b/OpenNest.Engine/Fill/Compactor.cs @@ -174,5 +174,28 @@ namespace OpenNest.Engine.Fill return 0; } + + /// + /// Repeatedly pushes parts left then down until total movement per + /// iteration falls below the given threshold. + /// + public static void Settle(List parts, Box workArea, double partSpacing, + double threshold = 0.01, int maxIterations = 20) + { + if (parts.Count < 2) + return; + + var noObstacles = new List(); + + for (var i = 0; i < maxIterations; i++) + { + var moved = 0.0; + moved += Push(parts, noObstacles, workArea, partSpacing, PushDirection.Left); + moved += Push(parts, noObstacles, workArea, partSpacing, PushDirection.Down); + + if (moved < threshold) + break; + } + } } }