From 0c14d7f854047a4568012e3735b8a7b7da8d866a Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Sat, 7 Mar 2026 19:24:37 -0500 Subject: [PATCH] fix: align best-fit sweep to include offset=0 for grid arrangements The perpendicular sweep started at perpMin (e.g. -8.75) which with coarse step sizes never landed on offset=0, missing the perfect side-by-side and stacked same-orientation patterns for rectangular parts. Co-Authored-By: Claude Opus 4.6 --- OpenNest.Engine/BestFit/RotationSlideStrategy.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/OpenNest.Engine/BestFit/RotationSlideStrategy.cs b/OpenNest.Engine/BestFit/RotationSlideStrategy.cs index 2447213..8cb6162 100644 --- a/OpenNest.Engine/BestFit/RotationSlideStrategy.cs +++ b/OpenNest.Engine/BestFit/RotationSlideStrategy.cs @@ -80,7 +80,12 @@ namespace OpenNest.Engine.BestFit // Pre-compute part1's offset lines (half-spacing outward) var part1Lines = Helper.GetOffsetPartLines(part1, halfSpacing); - for (var offset = perpMin; offset <= perpMax; offset += stepSize) + // Align sweep start to a multiple of stepSize so that offset=0 is always + // included. This ensures perfect grid arrangements (side-by-side, stacked) + // are generated for rectangular parts. + var alignedStart = System.Math.Ceiling(perpMin / stepSize) * stepSize; + + for (var offset = alignedStart; offset <= perpMax; offset += stepSize) { var part2 = (Part)part2Template.Clone();