Files
OpenNest/OpenNest.Engine/Strategies/ExtentsFillStrategy.cs
AJ Isaacs 0e1e619f0a refactor(engine): move fill and strategy code to dedicated namespaces
Move fill algorithms to OpenNest.Engine.Fill namespace:
FillLinear, FillExtents, PairFiller, ShrinkFiller, Compactor,
RemnantFiller, RemnantFinder, FillScore, Pattern, PatternTiler,
PartBoundary, RotationAnalysis, AngleCandidateBuilder, and
AccumulatingProgress.

Move strategy layer to OpenNest.Engine.Strategies namespace:
IFillStrategy, FillContext, FillStrategyRegistry, FillHelpers,
and all built-in strategy implementations.

Add using directives to all consuming files across Engine, UI,
MCP, and Tests projects.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 16:46:11 -04:00

46 lines
1.5 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 bestScore = default(FillScore);
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)
{
var score = FillScore.Compute(result, context.WorkArea);
if (best == null || score > bestScore)
{
best = result;
bestScore = score;
}
}
}
return best ?? new List<Part>();
}
}
}