Files
OpenNest/OpenNest.Engine/Strategies/TiltedRemnantStrategy.cs
T
ajandClaude Fable 5.2 3fccf6670f perf(irregular): remember outline overlap verdicts across a solve's fills
Auto Nest's banded variant fills the same box with the same part once per
remaining quantity, and each fill's tilted-remnant step triangulated and
tested the same spacing outlines at the same places: 98 s of a 271 s
profile of N26-2J9.

OutlineOverlapMemo keeps the verdict of SpacingOutline.Overlaps by the
exact coordinates of both perimeters, so a remembered answer is the one
the test would give and no layout can change. The block catalog owns one
memo per solve and passes it to its private fills; interactive fills pass
none and test every pair as before. It holds coordinates and verdicts
only, in two bounded generations.

N26-2J9 Auto Nest: 244 s to 179 s, the same plans and result.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 14:53:05 -05:00

48 lines
1.5 KiB
C#

using System.Collections.Generic;
using OpenNest.Engine.Fill;
using OpenNest.Math;
namespace OpenNest.Engine.Strategies;
/// <summary>
/// Runs after the other strategies and adds tilted parts beside their best layout, where the
/// leftover strip is too narrow for the part at 0 or 90 degrees. See <see cref="TiltedRemnantFiller"/>.
/// </summary>
public class TiltedRemnantStrategy : IFillStrategy
{
public string Name => "TiltedRemnant";
public NestPhase Phase => NestPhase.Custom;
public int Order => 500;
public List<Part> Fill(FillContext context)
{
var layout = context.CurrentBest;
if (layout == null || layout.Count == 0 || context.PartType == PartType.Circle)
return null;
// Tilting would break an explicit rotation range.
var item = context.Item;
if (!item.RotationStart.IsEqualTo(0) || !item.RotationEnd.IsEqualTo(0))
return null;
var target = context.MaxQuantity > 0 ? context.MaxQuantity : item.Quantity;
if (target > 0 && layout.Count >= target)
return null;
var filler = new TiltedRemnantFiller(
context.WorkArea,
context.Plate.PartSpacing,
context.Policy.Comparer
)
{
OverlapMemo = context.OverlapMemo,
};
var result = filler.Fill(item.Drawing, layout, context.Token);
if (result != null)
context.ReportProgress(result, $"Tilted remnant: {result.Count} parts");
return result;
}
}