refactor(engine): remove legacy nesting engine surface

This commit is contained in:
aj
2026-09-22 14:25:46 -04:00
parent 98c4929d14
commit e65f849c7a
30 changed files with 184 additions and 1119 deletions
+7 -10
View File
@@ -8,11 +8,10 @@ using System.Reflection;
namespace OpenNest.Engine.Jobs;
/// <summary>
/// Registry of whole-job INestingEngine implementations, parallel to NestEngineRegistry (which is for
/// the legacy single-plate NestEngineBase). The four production strategies are exposed here through
/// FixedStrategyNestingEngine so they compete on equal footing with model-submitted engines. Unlike
/// NestEngineRegistry, this has no ActiveEngineName/global-selection concept — callers choose an engine
/// explicitly from AvailableEngines.
/// Registry of whole-job <see cref="INestingEngine"/> implementations. The four production
/// strategies are exposed through <see cref="FixedStrategyNestingEngine"/> so they compete on
/// equal footing with model-submitted engines. Callers choose an engine explicitly from
/// <see cref="AvailableEngines"/>; there is no process-global active selection.
/// </summary>
public static class NestingEngineRegistry
{
@@ -55,8 +54,7 @@ public static class NestingEngineRegistry
/// <summary>
/// Creates the engine registered under <paramref name="name"/> (case-insensitive). The caller's
/// explicit choice is the whole selection mechanism: unlike the legacy registry there is no
/// process-global active name to consult or mutate. Unknown names throw.
/// explicit choice is the whole selection mechanism; unknown names throw.
/// </summary>
public static INestingEngine Create(string name)
{
@@ -81,9 +79,8 @@ public static class NestingEngineRegistry
}
/// <summary>Scans *.dll in directory for non-abstract INestingEngine types with a public
/// parameterless constructor, registering each under its CLR type name. Mirrors
/// NestEngineRegistry.LoadPlugins's per-assembly/per-type isolation: one bad plugin never
/// prevents the rest from loading.</summary>
/// parameterless constructor, registering each under its CLR type name. Per-assembly and per-type
/// isolation ensures one bad plugin never prevents the rest from loading.</summary>
public static void LoadPlugins(string directory)
{
if (!Directory.Exists(directory))
@@ -20,9 +20,7 @@ internal class DefaultPlateFiller : PlateFillerBase
internal DefaultPlateFiller(Plate plate)
: base(plate) { }
protected override IFillComparer CreateComparer() => CreateComparerCore();
internal IFillComparer CreateComparerCore() => new DefaultFillComparer();
protected override IFillComparer CreateComparer() => new DefaultFillComparer();
internal bool ForceFullAngleSweep
{
@@ -34,18 +32,9 @@ internal class DefaultPlateFiller : PlateFillerBase
NestItem item,
ClassificationResult classification,
Box workArea
) => BuildAnglesCore(item, classification, workArea);
internal List<double> BuildAnglesCore(
NestItem item,
ClassificationResult classification,
Box workArea
) => angleBuilder.Build(item, classification, workArea);
protected override void RecordProductiveAngles(List<AngleResult> angleResults) =>
RecordProductiveAnglesCore(angleResults);
internal void RecordProductiveAnglesCore(List<AngleResult> angleResults)
protected override void RecordProductiveAngles(List<AngleResult> angleResults)
{
angleBuilder.RecordProductive(angleResults);
}
@@ -419,9 +408,7 @@ internal class DefaultPlateFiller : PlateFillerBase
return BinConverter.ToParts(bin, items);
}
protected virtual void RunPipeline(FillContext context) => RunPipelineCore(context);
internal void RunPipelineCore(FillContext context)
protected virtual void RunPipeline(FillContext context)
{
var classification = PartClassifier.Classify(context.Item.Drawing);
context.PartType = classification.Type;
@@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using OpenNest.Engine;
using OpenNest.Engine.Fill;
using OpenNest.Engine.Strategies;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest.Engine.Jobs.Placement.Fillers;
@@ -27,11 +25,6 @@ internal abstract class PlateFillerBase
public NestPhase WinnerPhase { get; protected set; }
internal void SetWinnerPhase(NestPhase winnerPhase)
{
WinnerPhase = winnerPhase;
}
public List<PhaseResult> PhaseResults { get; } = new();
public List<AngleResult> AngleResults { get; } = new();
@@ -61,11 +54,9 @@ internal abstract class PlateFillerBase
protected FillPolicy BuildPolicy() => new(Comparer, PreferredDirection);
internal IFillComparer FillComparer => Comparer;
protected string BuildProgressSummary() => BuildProgressSummary(PhaseResults);
internal static string BuildProgressSummary(IReadOnlyList<PhaseResult> phaseResults)
private static string BuildProgressSummary(IReadOnlyList<PhaseResult> phaseResults)
{
if (phaseResults.Count == 0)
return null;
@@ -78,70 +69,7 @@ internal abstract class PlateFillerBase
}
protected bool IsBetterFill(List<Part> candidate, List<Part> current, Box workArea) =>
IsBetterFill(Comparer, candidate, current, workArea);
internal static bool IsBetterFill(
IFillComparer comparer,
List<Part> candidate,
List<Part> current,
Box workArea
) => comparer.IsBetter(candidate, current, workArea);
protected bool IsBetterValidFill(List<Part> candidate, List<Part> current, Box workArea)
{
if (
candidate != null
&& candidate.Count > 0
&& HasOverlaps(candidate, Plate.PartSpacing)
)
{
Debug.WriteLine(
$"[IsBetterValidFill] REJECTED {candidate.Count} parts due to overlaps (current best: {current?.Count ?? 0})"
);
return false;
}
return IsBetterFill(candidate, current, workArea);
}
internal static bool HasOverlaps(List<Part> parts, double spacing)
{
if (parts == null || parts.Count <= 1)
return false;
for (var i = 0; i < parts.Count; i++)
{
var box1 = parts[i].BoundingBox;
for (var j = i + 1; j < parts.Count; j++)
{
var box2 = parts[j].BoundingBox;
var overlapX = System.Math.Min(box1.Right, box2.Right)
- System.Math.Max(box1.Left, box2.Left);
var overlapY = System.Math.Min(box1.Top, box2.Top)
- System.Math.Max(box1.Bottom, box2.Bottom);
if (overlapX <= Tolerance.Epsilon || overlapY <= Tolerance.Epsilon)
continue;
List<Vector> points;
if (parts[i].Intersects(parts[j], out points))
{
var first = parts[i].BoundingBox;
var second = parts[j].BoundingBox;
Debug.WriteLine(
$"[HasOverlaps] Overlap: part[{i}] ({parts[i].BaseDrawing?.Name}) @ ({first.Left:F2},{first.Bottom:F2})-({first.Right:F2},{first.Top:F2}) rot={parts[i].Rotation:F2}"
+ $" vs part[{j}] ({parts[j].BaseDrawing?.Name}) @ ({second.Left:F2},{second.Bottom:F2})-({second.Right:F2},{second.Top:F2}) rot={parts[j].Rotation:F2}"
+ $" intersections={points?.Count ?? 0}"
);
return true;
}
}
}
return false;
}
Comparer.IsBetter(candidate, current, workArea);
public virtual List<Part> Fill(
NestItem item,
@@ -40,13 +40,6 @@ internal class StripPlateFiller : PlateFillerBase
List<NestItem> items,
IProgress<NestProgress> progress,
CancellationToken token
) => PackAreaCore(box, items, progress, token);
internal List<Part> PackAreaCore(
Box box,
List<NestItem> items,
IProgress<NestProgress> progress,
CancellationToken token
)
{
var inner = new DefaultPlateFiller(Plate);
+2 -3
View File
@@ -5,9 +5,8 @@ namespace OpenNest.Engine.Jobs;
/// <summary>
/// Instance-scoped strategy resolution for the whole-job runner. All four built-in strategies
/// resolve directly to filler-backed plate nesters. The process-global NestEngineRegistry
/// (including plugin registrations and ActiveEngineName) is neither read nor modified.
/// Unknown keys reject.
/// resolve directly to filler-backed plate nesters. Selection is explicit per job; no shared
/// mutable strategy setting is read or modified. Unknown keys reject.
/// </summary>
public static class PlateNesterFactory
{