feat: add reverse push directions for concave interlocking and cache best-fit results

Add PushDirection.Right and PushDirection.Up to RotationSlideStrategy so
parts can approach from all four directions. This discovers concave
interlocking arrangements (e.g. L-shaped parts nesting into each other's
cavities) that the original Left/Down-only slides could never reach.

Introduce BestFitCache so best-fit results are computed once at step size
0.25 and shared between the viewer and nesting engine. The GPU evaluator
factory is configured once at startup instead of being wired per call
site, and NestEngine.CreateEvaluator is removed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 14:02:41 -04:00
parent 031264e98f
commit 3220306d3a
8 changed files with 126 additions and 28 deletions

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using OpenNest.Engine.BestFit;
@@ -20,8 +19,6 @@ namespace OpenNest
public NestDirection NestDirection { get; set; }
public Func<Drawing, double, IPairEvaluator> CreateEvaluator { get; set; }
public bool Fill(NestItem item)
{
return Fill(item, Plate.WorkArea());
@@ -151,16 +148,9 @@ namespace OpenNest
private List<Part> FillWithPairs(NestItem item, Box workArea)
{
IPairEvaluator evaluator = null;
if (CreateEvaluator != null)
{
try { evaluator = CreateEvaluator(item.Drawing, Plate.PartSpacing); }
catch { /* GPU not available, fall back to geometry */ }
}
var finder = new BestFitFinder(Plate.Size.Width, Plate.Size.Height, evaluator);
var bestFits = finder.FindBestFits(item.Drawing, Plate.PartSpacing, stepSize: 0.25);
var bestFits = BestFitCache.GetOrCompute(
item.Drawing, Plate.Size.Width, Plate.Size.Height,
Plate.PartSpacing);
var keptResults = bestFits.Where(r => r.Keep).Take(50).ToList();
Debug.WriteLine($"[FillWithPairs] Total: {bestFits.Count}, Kept: {bestFits.Count(r => r.Keep)}, Trying: {keptResults.Count}");
@@ -187,8 +177,6 @@ namespace OpenNest
best = parts;
}
(evaluator as IDisposable)?.Dispose();
Debug.WriteLine($"[FillWithPairs] Best pair result: {best?.Count ?? 0} parts");
return best ?? new List<Part>();
}