Files
OpenNest/OpenNest.Engine/Strategies/ExtentsFillStrategy.cs
AJ Isaacs 24beb8ada1 feat: wire IFillComparer through FillHelpers, Linear, and Extents strategies
- FillHelpers.FillPattern gains optional IFillComparer parameter; falls back to FillScore when null
- LinearFillStrategy.Fill replaced with FillWithDirectionPreference + comparer from context.Policy
- ExtentsFillStrategy.Fill replaced with comparer.IsBetter, removing FillScore comparison
- DefaultNestEngine group-fill path resolves Task 6 TODO, passing Comparer to FillPattern

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-21 12:49:59 -04:00

42 lines
1.4 KiB
C#

using OpenNest.Engine.Fill;
using OpenNest.Math;
using System.Collections.Generic;
namespace OpenNest.Engine.Strategies
{
public class ExtentsFillStrategy : IFillStrategy
{
public string Name => "Extents";
public NestPhase Phase => NestPhase.Extents;
public int Order => 300;
public List<Part> Fill(FillContext context)
{
var filler = new FillExtents(context.WorkArea, context.Plate.PartSpacing);
var bestRotation = context.SharedState.TryGetValue("BestRotation", out var rot)
? (double)rot
: RotationAnalysis.FindBestRotation(context.Item);
var angles = new[] { bestRotation, bestRotation + Angle.HalfPI };
List<Part> best = null;
var comparer = context.Policy?.Comparer ?? new DefaultFillComparer();
foreach (var angle in angles)
{
context.Token.ThrowIfCancellationRequested();
var result = filler.Fill(context.Item.Drawing, angle,
context.PlateNumber, context.Token, context.Progress);
if (result != null && result.Count > 0)
{
if (best == null || comparer.IsBetter(result, best, context.WorkArea))
best = result;
}
}
return best ?? new List<Part>();
}
}
}