refactor: extract responsibilities from NestEngine into focused classes

- Move BuildPairParts to BestFitResult.BuildParts() instance method
- Extract BinConverter (RectanglePacking) for Part/NestItem/Bin conversions
- Extract RotationAnalysis for FindBestRotation and FindHullEdgeAngles

NestEngine reduced from 484 to 287 lines — now purely orchestration,
strategy selection, and comparison logic.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 21:37:50 -05:00
parent b738d4c72c
commit 99edad4228
6 changed files with 232 additions and 210 deletions

View File

@@ -1,3 +1,7 @@
using System.Collections.Generic;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest.Engine.BestFit
{
public class BestFitResult
@@ -25,6 +29,30 @@ namespace OpenNest.Engine.BestFit
{
get { return System.Math.Min(BoundingWidth, BoundingHeight); }
}
public List<Part> BuildParts(Drawing drawing)
{
var part1 = Part.CreateAtOrigin(drawing);
var part2 = Part.CreateAtOrigin(drawing, Candidate.Part2Rotation);
part2.Location = Candidate.Part2Offset;
part2.UpdateBounds();
if (!OptimalRotation.IsEqualTo(0))
{
var pairBounds = ((IEnumerable<IBoundable>)new IBoundable[] { part1, part2 }).GetBoundingBox();
var center = pairBounds.Center;
part1.Rotate(-OptimalRotation, center);
part2.Rotate(-OptimalRotation, center);
}
var finalBounds = ((IEnumerable<IBoundable>)new IBoundable[] { part1, part2 }).GetBoundingBox();
var offset = new Vector(-finalBounds.Left, -finalBounds.Bottom);
part1.Offset(offset);
part2.Offset(offset);
return new List<Part> { part1, part2 };
}
}
public enum BestFitSortField