refactor(engine): make jobs plate nesters filler-backed

This commit is contained in:
aj
2026-09-21 18:08:25 -04:00
parent 073ead9b79
commit eb8fbec1aa
12 changed files with 401 additions and 345 deletions
@@ -9,8 +9,8 @@ namespace OpenNest.Engine.Tests.Jobs;
/// <summary>
/// Golden-layout fixtures: the permanent regression net for the legacy-engine removal.
/// Each test solves a fixed job through the production path
/// (<see cref="PlateNesterFactory"/> + <see cref="NestJobRunner"/>, which for the remnant
/// strategies still routes through <see cref="LegacyPlateNesterAdapter"/>) and asserts the
/// (<see cref="PlateNesterFactory"/> + <see cref="NestJobRunner"/>, all four strategies
/// filler-backed) and asserts the
/// exact committed poses captured from the pre-migration code. The extraction phases must
/// keep these green byte-for-byte (modulo 1e-9 float noise).
/// </summary>
+6 -131
View File
@@ -5,125 +5,13 @@ using OpenNest.Engine.Jobs.Adapters;
namespace OpenNest.Engine.Tests.Jobs;
/// <summary>
/// Domain-boundary adapters: geometry snapshots, mapper round-trips, and materialization. The
/// former adapter-vs-runner contract tests moved to <see cref="NesterContractTests"/> when the
/// legacy plate-nester adapter was deleted in the jobs-only placement migration.
/// </summary>
public class JobAdapterTests
{
[Fact]
public void LegacyMutationsCannotDoubleSubtractOrReachCallerObjects()
{
var drawing = new Drawing("same name", TestDrawingFactory.Rectangle());
drawing.Quantity.Required = 9;
var item = new NestItem
{
Drawing = drawing,
Quantity = 3,
Priority = 7,
StepAngle = 0,
};
var sourcePlate = new Plate(100, 200) { Quantity = 3, PartSpacing = 2 };
var job = new NestJob(
new[] { DrawingJobMapper.FromItem("requirement", item) },
new[] { DrawingJobMapper.FromPlate("stock", sourcePlate, 3) }
);
var quantities = new List<int>();
var adapter = new LegacyPlateNesterAdapter(p => new MutatingEngine(
p,
items =>
{
var privateItem = Assert.Single(items);
quantities.Add(privateItem.Quantity);
Assert.NotSame(drawing, privateItem.Drawing);
Assert.Equal(0, privateItem.StepAngle);
Assert.Equal(7, privateItem.Priority);
var part = new Part(privateItem.Drawing);
privateItem.Quantity = 0;
privateItem.Drawing.Quantity.Required = 0;
return new List<Part> { part };
}
));
var result = new NestJobRunner(_ => adapter).Solve(job);
var materialized = NestResultMaterializer.Materialize(job, result);
Assert.Equal(new[] { 3, 2, 1 }, quantities);
Assert.Equal(NestJobStatus.Complete, result.Status);
Assert.Equal(3, materialized.Nest.Plates.Count);
Assert.All(
materialized.Nest.Plates,
p =>
{
Assert.Equal(1, p.Quantity);
Assert.Single(p.Parts);
}
);
var outputDrawing = materialized.DrawingsByPartId["requirement"];
Assert.Equal(3, outputDrawing.Quantity.Required);
Assert.Equal(3, outputDrawing.Quantity.Nested);
Assert.All(
materialized.Nest.Plates,
p => Assert.Same(outputDrawing, p.Parts[0].BaseDrawing)
);
Assert.NotSame(drawing, outputDrawing);
Assert.Equal(9, drawing.Quantity.Required);
Assert.Equal(0, drawing.Quantity.Nested);
Assert.Equal(3, item.Quantity);
Assert.Equal(3, sourcePlate.Quantity);
Assert.Empty(sourcePlate.Parts);
Assert.Equal(2, sourcePlate.PartSpacing);
Assert.Equal(
PartGeometrySnapshot.FromProgram(TestDrawingFactory.Rectangle()).Motions,
PartGeometrySnapshot.FromProgram(drawing.Program).Motions
);
}
[Fact]
public void ReferenceIdentityNotNamesControlsLegacyPlacements()
{
var drawing = new Drawing("duplicate", TestDrawingFactory.Rectangle());
var job = new NestJob(
new[]
{
DrawingJobMapper.FromDrawing("a", drawing, 1),
DrawingJobMapper.FromDrawing("b", drawing, 1),
},
FiniteStockJobTests.Job(1).Plates
);
var adapter = new LegacyPlateNesterAdapter(p => new MutatingEngine(
p,
items =>
{
Assert.NotSame(items[0].Drawing, items[1].Drawing);
foreach (var item in items)
item.Drawing.Name = "identical";
return new List<Part>
{
new Part(items[0].Drawing, new Vector(0, 0)),
new Part(items[1].Drawing, new Vector(10, 0)),
};
}
));
var result = new NestJobRunner(_ => adapter).Solve(job);
Assert.Equal(new[] { "a", "b" }, result.Plates[0].Placements.Select(p => p.PartId));
var output = NestResultMaterializer.Materialize(job, result);
Assert.NotSame(output.DrawingsByPartId["a"], output.DrawingsByPartId["b"]);
Assert.All(output.DrawingsByPartId.Values, d => Assert.Equal(1, d.Quantity.Nested));
}
[Fact]
public void UnknownPrivateDrawingIsRejectedEvenWithMatchingName()
{
var adapter = new LegacyPlateNesterAdapter(p => new MutatingEngine(
p,
items => new List<Part>
{
new(new Drawing(items[0].Drawing.Name, TestDrawingFactory.Rectangle())),
}
));
Assert.Throws<InvalidOperationException>(() =>
new NestJobRunner(_ => adapter).Solve(FiniteStockJobTests.Job())
);
Assert.Throws<NotSupportedException>(() =>
LegacyPlateNesterAdapter.Create("not registered")
);
}
[Fact]
public void ExactGeometryRoundTripsIncludingOriginArcHoleAndMode()
{
@@ -167,7 +55,7 @@ public class JobAdapterTests
new[] { DrawingJobMapper.FromDrawing("rectangle", drawing, 1) },
new[] { new NestPlateStock("sheet", new Size(40, 60), 1, 1, new Spacing(2, 2, 2, 2)) }
);
var result = new NestJobRunner(LegacyPlateNesterAdapter.Create).Solve(job);
var result = new NestJobRunner(PlateNesterFactory.Create).Solve(job);
Assert.Equal(NestJobStatus.Complete, result.Status);
Assert.Equal(new StockUsage("sheet", 1, 0), Assert.Single(result.StockUsage));
var pose = Assert.Single(Assert.Single(result.Plates).Placements);
@@ -207,17 +95,4 @@ public class JobAdapterTests
Assert.Equal(expected.Y, ((Motion)part.Program.Codes[0]).EndPoint.Y, 10);
Assert.Equal(new Vector(23, 31), part.Location);
}
private sealed class MutatingEngine(Plate plate, Func<List<NestItem>, List<Part>> nest)
: NestEngineBase(plate)
{
public override string Name => "test";
public override string Description => "mutates private demand";
public override List<Part> Nest(
List<NestItem> items,
IProgress<NestProgress> progress,
CancellationToken token
) => nest(items);
}
}
@@ -1,7 +1,8 @@
using OpenNest.CNC;
using OpenNest.Geometry;
using OpenNest.Engine.Jobs;
using OpenNest.Engine.Jobs.Adapters;
using OpenNest.Engine.Jobs.Placement;
using OpenNest.Engine.Jobs.Placement.Fillers;
namespace OpenNest.Engine.Tests.Jobs;
@@ -84,9 +85,9 @@ public class NestJobCancellationTests
new[] { part },
new[] { new NestPlateStock("stock", new Size(20, 30), 1) }
);
var runner = new NestJobRunner(_ => new LegacyPlateNesterAdapter(
plate => new ReportingEngine(plate)
));
var runner = new NestJobRunner(_ => new DefaultPlateNester(plate => new ReportingFiller(
plate
)));
var result = runner.Solve(job, new InlineProgress(reports.Add));
@@ -134,11 +135,8 @@ public class NestJobCancellationTests
}
}
private sealed class ReportingEngine(Plate plate) : NestEngineBase(plate)
private sealed class ReportingFiller(Plate plate) : DefaultPlateFiller(plate)
{
public override string Name => "reporting";
public override string Description => "reports progress";
public override List<Part> Nest(
List<NestItem> items,
IProgress<NestProgress>? progress,
@@ -1,15 +1,18 @@
using OpenNest.CNC;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using OpenNest.Engine.Jobs;
using OpenNest.Engine.Jobs.Adapters;
using OpenNest.Engine.Jobs.Placement;
using OpenNest.Engine.Jobs.Placement.Fillers;
namespace OpenNest.Engine.Tests.Jobs;
/// <summary>
/// Names are never identity: two distinct drawings that share a display name must keep
/// independent quantities, and two requirements that share one source drawing must not
/// cross-count each other's placements through the legacy engine paths.
/// cross-count each other's placements. Production identity runs through the built-in nesters'
/// <see cref="CandidatePlacementContext"/>; the filler probes exercise the orchestrator's
/// reference-identity quantity deduction directly.
/// </summary>
public class NestJobIdentityTests
{
@@ -27,7 +30,7 @@ public class NestJobIdentityTests
new[] { new NestPlateStock("s", new Size(90, 90), 1) }
);
var result = new NestJobRunner(LegacyPlateNesterAdapter.Create).Solve(job);
var result = new NestJobRunner(PlateNesterFactory.Create).Solve(job);
// Every placed part maps to a known requirement ID; no part is invented or cross-counted.
Assert.True(result.Plates.SelectMany(p => p.Placements).All(p => p.PartId is "a" or "b"));
@@ -56,7 +59,7 @@ public class NestJobIdentityTests
new[] { new NestPlateStock("s", new Size(90, 90), 1) }
);
var result = new NestJobRunner(LegacyPlateNesterAdapter.Create).Solve(job);
var result = new NestJobRunner(PlateNesterFactory.Create).Solve(job);
Assert.Equal(new[] { "first", "second" }, result.Fulfillment.Select(f => f.PartId));
foreach (var f in result.Fulfillment)
@@ -72,7 +75,7 @@ public class NestJobIdentityTests
[Fact]
public void EngineDeductionCountsByDrawingReferenceNotName()
{
// Plate 90x40 fits exactly two 40x40 parts. The engine fills item A with both and
// Plate 90x40 fits exactly two 40x40 parts. The filler fills item A with both and
// starves item B. Name-based deduction would then zero BOTH items (the two placed
// parts carry the shared name, so each item counts 2 as "its own"). Reference-based
// deduction leaves B at 2.
@@ -84,7 +87,7 @@ public class NestJobIdentityTests
new() { Drawing = a, Quantity = 2 },
new() { Drawing = b, Quantity = 2 },
};
// Place exactly 2 parts from item A and none from item B, then run the base-class
// Place exactly 2 parts from item A and none from item B, then run the orchestrator's
// deduction. Deterministic regardless of any fill heuristic.
var placed = new StarvingProbe(plate).Nest(items, null, default);
@@ -111,45 +114,41 @@ public class NestJobIdentityTests
new() { Drawing = a, Quantity = 1 },
new() { Drawing = b, Quantity = 1 },
};
var placed = new BaseNestEngineProbe(plate).Nest(items, null, default);
var placed = new DefaultFillerProbe(plate).Nest(items, null, default);
Assert.Equal(2, placed.Count);
Assert.Equal(new[] { 0, 0 }, new[] { items[0].Quantity, items[1].Quantity });
}
private sealed class BaseNestEngineProbe(Plate plate) : NestEngineBase(plate)
/// <summary>Orchestrator probe whose fill/pack delegates run the Default filler.</summary>
private sealed class DefaultFillerProbe(Plate plate) : PlateFillerBase(plate)
{
public override string Name => "probe";
public override string Description => "probe";
public override List<Part> Fill(
NestItem item,
Box workArea,
IProgress<NestProgress> progress,
CancellationToken token
) => new DefaultNestEngine(Plate).Fill(item, workArea, progress, token);
) => new DefaultPlateFiller(Plate).Fill(item, workArea, progress, token);
public override List<Part> Fill(
List<Part> groupParts,
Box workArea,
IProgress<NestProgress> progress,
CancellationToken token
) => new DefaultNestEngine(Plate).Fill(groupParts, workArea, progress, token);
) => new DefaultPlateFiller(Plate).Fill(groupParts, workArea, progress, token);
public override List<Part> PackArea(
Box box,
List<NestItem> items,
IProgress<NestProgress> progress,
CancellationToken token
) => new DefaultNestEngine(Plate).PackArea(box, items, progress, token);
) => new DefaultPlateFiller(Plate).PackArea(box, items, progress, token);
}
/// <summary>Places exactly 2 parts from the first multi-quantity item and none from the
/// rest, forcing the base-class deduction to run on an asymmetric placement result.</summary>
private sealed class StarvingProbe(Plate plate) : NestEngineBase(plate)
/// rest, forcing the orchestrator's deduction to run on an asymmetric placement result.</summary>
private sealed class StarvingProbe(Plate plate) : PlateFillerBase(plate)
{
private int _first = -1;
public override string Name => "starving";
public override string Description => "starves all but the first fill item";
public override List<Part> Fill(
NestItem item,
@@ -0,0 +1,180 @@
using OpenNest.CNC;
using OpenNest.Geometry;
using OpenNest.Engine.Jobs;
using OpenNest.Engine.Jobs.Adapters;
namespace OpenNest.Engine.Tests.Jobs;
/// <summary>
/// The jobs-boundary contract that <see cref="CandidatePlacementContext"/> and
/// <see cref="NestJobRunner"/> share with every <see cref="IPlateNester"/>. Retargeted from the
/// deleted legacy adapter's tests: the private-geometry, reference-identity, and unknown-part
/// guarantees are boundary properties, so they are proven with a nester stub that mutates its
/// private items exactly as an engine would.
/// </summary>
public class NesterContractTests
{
[Fact]
public void NesterMutationsCannotDoubleSubtractOrReachCallerObjects()
{
var drawing = new Drawing("same name", TestDrawingFactory.Rectangle());
drawing.Quantity.Required = 9;
var item = new NestItem
{
Drawing = drawing,
Quantity = 3,
Priority = 7,
StepAngle = 0,
};
var sourcePlate = new Plate(100, 200) { Quantity = 3, PartSpacing = 2 };
var job = new NestJob(
new[] { DrawingJobMapper.FromItem("requirement", item) },
new[] { DrawingJobMapper.FromPlate("stock", sourcePlate, 3) }
);
var quantities = new List<int>();
var nester = new RecordingNester(
items =>
{
var privateItem = Assert.Single(items);
quantities.Add(privateItem.Quantity);
Assert.NotSame(drawing, privateItem.Drawing);
Assert.Equal(0, privateItem.StepAngle);
Assert.Equal(7, privateItem.Priority);
var part = new Part(privateItem.Drawing);
privateItem.Quantity = 0;
privateItem.Drawing.Quantity.Required = 0;
return new List<Part> { part };
}
);
var result = new NestJobRunner(_ => nester).Solve(job);
var materialized = NestResultMaterializer.Materialize(job, result);
Assert.Equal(new[] { 3, 2, 1 }, quantities);
Assert.Equal(NestJobStatus.Complete, result.Status);
Assert.Equal(3, materialized.Nest.Plates.Count);
Assert.All(
materialized.Nest.Plates,
p =>
{
Assert.Equal(1, p.Quantity);
Assert.Single(p.Parts);
}
);
var outputDrawing = materialized.DrawingsByPartId["requirement"];
Assert.Equal(3, outputDrawing.Quantity.Required);
Assert.Equal(3, outputDrawing.Quantity.Nested);
Assert.All(
materialized.Nest.Plates,
p => Assert.Same(outputDrawing, p.Parts[0].BaseDrawing)
);
Assert.NotSame(drawing, outputDrawing);
Assert.Equal(9, drawing.Quantity.Required);
Assert.Equal(0, drawing.Quantity.Nested);
Assert.Equal(3, item.Quantity);
Assert.Equal(3, sourcePlate.Quantity);
Assert.Empty(sourcePlate.Parts);
Assert.Equal(2, sourcePlate.PartSpacing);
Assert.Equal(
PartGeometrySnapshot.FromProgram(TestDrawingFactory.Rectangle()).Motions,
PartGeometrySnapshot.FromProgram(drawing.Program).Motions
);
}
[Fact]
public void ReferenceIdentityNotNamesControlsPlacements()
{
var drawing = new Drawing("duplicate", TestDrawingFactory.Rectangle());
var job = new NestJob(
new[]
{
DrawingJobMapper.FromDrawing("a", drawing, 1),
DrawingJobMapper.FromDrawing("b", drawing, 1),
},
FiniteStockJobTests.Job(1).Plates
);
var nester = new RecordingNester(
items =>
{
Assert.NotSame(items[0].Drawing, items[1].Drawing);
foreach (var item in items)
item.Drawing.Name = "identical";
return new List<Part>
{
new Part(items[0].Drawing, new Vector(0, 0)),
new Part(items[1].Drawing, new Vector(10, 0)),
};
}
);
var result = new NestJobRunner(_ => nester).Solve(job);
Assert.Equal(new[] { "a", "b" }, result.Plates[0].Placements.Select(p => p.PartId));
var output = NestResultMaterializer.Materialize(job, result);
Assert.NotSame(output.DrawingsByPartId["a"], output.DrawingsByPartId["b"]);
Assert.All(output.DrawingsByPartId.Values, d => Assert.Equal(1, d.Quantity.Nested));
}
[Fact]
public void UnknownPrivateDrawingIsRejectedEvenWithMatchingName()
{
var nester = new RecordingNester(
items =>
new List<Part>
{
new(new Drawing(items[0].Drawing.Name, TestDrawingFactory.Rectangle())),
}
);
Assert.Throws<InvalidOperationException>(() =>
new NestJobRunner(_ => nester).Solve(FiniteStockJobTests.Job())
);
Assert.Throws<NotSupportedException>(() => PlateNesterFactory.Create("not registered"));
}
/// <summary>Runs a caller-supplied function over freshly built private items and maps the
/// returned parts back by Drawing reference — the same boundary mechanics as the production
/// <see cref="CandidatePlacementContext"/>, but rebuilt per call so each trial is independent.</summary>
private sealed class RecordingNester(Func<List<NestItem>, List<Part>> propose) : IPlateNester
{
public PlateCandidate Place(
PlatePlacementRequest request,
IProgress<NestJobProgress>? progress = null,
CancellationToken token = default
)
{
var items = new List<NestItem>();
var idsByDrawing = new Dictionary<Drawing, string>(ReferenceEqualityComparer.Instance);
foreach (var requirement in request.Parts)
{
var drawing = DrawingJobMapper.CreateDrawing(requirement);
idsByDrawing.Add(drawing, requirement.Id);
items.Add(
new NestItem
{
Drawing = drawing,
Quantity = requirement.Quantity,
Priority = requirement.Priority,
StepAngle = DrawingJobMapper.LegacyStep(requirement.Rotation),
RotationStart = requirement.Rotation.Start,
RotationEnd = requirement.Rotation.End,
}
);
}
return new PlateCandidate(
propose(items).Select(p => new NestJobPlacement(
IdFor(idsByDrawing, p),
0,
p.Location.X,
p.Location.Y,
p.Rotation
))
);
}
private static string IdFor(Dictionary<Drawing, string> idsByDrawing, Part part)
{
// Deliberately reference-based, like the placement context.
if (part?.BaseDrawing == null || !idsByDrawing.TryGetValue(part.BaseDrawing, out var id))
throw new InvalidOperationException(
"Placement does not reference a known requirement drawing."
);
return id;
}
}
}
@@ -2,16 +2,15 @@ using OpenNest.CNC;
using OpenNest.Geometry;
using Xunit;
using OpenNest.Engine.Jobs;
using OpenNest.Engine.Jobs.Adapters;
using OpenNest.Engine.Jobs.Placement;
namespace OpenNest.Engine.Tests.Jobs;
/// <summary>
/// Parity between the legacy adapter and the migrated built-in plate nesters (Default/Strip) on
/// generated geometry. The runner's placement validator enforces geometric safety on every committed
/// candidate, so these tests assert fulfillment, status, and — for the deterministic Default/rectangle
/// case — identical layouts.
/// Direct filler-backed coverage for the built-in plate nesters (Default/Strip/remnant). The
/// runner's placement validator enforces geometric safety on every committed candidate, so these
/// tests assert fulfillment, status, and the identity/rotation safety boundaries; exact committed
/// layouts are pinned separately by <see cref="GoldenLayoutTests"/>.
/// </summary>
public class PlateNesterParityTests
{
@@ -36,29 +35,6 @@ public class PlateNesterParityTests
private static Dictionary<string, PartFulfillment> ByPart(NestJobResult result) =>
result.Fulfillment.ToDictionary(f => f.PartId, StringComparer.Ordinal);
private static void AssertLayoutsIdentical(NestJobResult left, NestJobResult right)
{
Assert.Equal(left.Plates.Count, right.Plates.Count);
for (var i = 0; i < left.Plates.Count; i++)
{
var lPlates = left.Plates[i].Placements;
var rPlates = right.Plates[i].Placements;
Assert.Equal(lPlates.Count, rPlates.Count);
var lSorted = lPlates.OrderBy(p => p.PartId).ThenBy(p => p.X).ThenBy(p => p.Y).ToList();
var rSorted = rPlates.OrderBy(p => p.PartId).ThenBy(p => p.X).ThenBy(p => p.Y).ToList();
for (var j = 0; j < lSorted.Count; j++)
{
Assert.Equal(lSorted[j].PartId, rSorted[j].PartId);
Assert.Equal(lSorted[j].X, rSorted[j].X, 6);
Assert.Equal(lSorted[j].Y, rSorted[j].Y, 6);
Assert.True(
AnglesEqual(lSorted[j].Rotation, rSorted[j].Rotation),
$"rotation differs: {lSorted[j].Rotation} vs {rSorted[j].Rotation}"
);
}
}
}
private static bool AnglesEqual(double left, double right)
{
var delta = (left - right) % (System.Math.PI * 2);
@@ -67,7 +43,7 @@ public class PlateNesterParityTests
}
[Fact]
public void DefaultParity_Rectangles_SameFulfillmentAndLayout()
public void DefaultDirectFiller_Rectangles_FulfilledAndValid()
{
var parts = new[]
{
@@ -83,26 +59,18 @@ public class PlateNesterParityTests
),
};
var legacy = Solve(
new LegacyPlateNesterAdapter(plate => new DefaultNestEngine(plate)),
Job(parts)
);
var migrated = Solve(new DefaultPlateNester(), Job(parts));
var result = Solve(new DefaultPlateNester(), Job(parts));
Assert.Equal(legacy.Status, migrated.Status);
Assert.Equal(NestJobStatus.Complete, migrated.Status);
Assert.Equal(ByPart(legacy), ByPart(migrated));
foreach (var usage in legacy.StockUsage)
Assert.Equal(
usage.Used,
migrated.StockUsage.First(u => u.StockId == usage.StockId).Used
);
// Automatic-rotation rectangles on a single stock size are deterministic: identical layouts.
AssertLayoutsIdentical(legacy, migrated);
Assert.Equal(NestJobStatus.Complete, result.Status);
Assert.Equal(4, ByPart(result)["a"].Placed);
Assert.Equal(3, ByPart(result)["b"].Placed);
var usage = Assert.Single(result.StockUsage);
Assert.Equal(1, usage.Used);
Assert.Equal(7, result.Plates.SelectMany(p => p.Placements).Count());
}
[Fact]
public void StripParity_Rectangles_SameFulfillmentAndTotalCount()
public void StripDirectFiller_Rectangles_FulfilledAndValid()
{
var parts = new[]
{
@@ -118,29 +86,22 @@ public class PlateNesterParityTests
),
};
var legacy = Solve(
new LegacyPlateNesterAdapter(plate => new StripNestEngine(plate)),
Job(parts, strategy: "Strip")
);
var migrated = Solve(new StripPlateNester(), Job(parts, strategy: "Strip"));
var result = Solve(new StripPlateNester(), Job(parts, strategy: "Strip"));
Assert.Equal(legacy.Status, migrated.Status);
Assert.Equal(NestJobStatus.Complete, migrated.Status);
Assert.Equal(ByPart(legacy), ByPart(migrated));
Assert.Equal(
legacy.Plates.SelectMany(p => p.Placements).Count(),
migrated.Plates.SelectMany(p => p.Placements).Count()
);
// Shrink-fill ordering can differ between engine instances; do not assert identical coordinates.
Assert.Equal(NestJobStatus.Complete, result.Status);
Assert.Equal(4, ByPart(result)["a"].Placed);
Assert.Equal(3, ByPart(result)["b"].Placed);
Assert.Equal(7, result.Plates.SelectMany(p => p.Placements).Count());
}
[Fact]
public void MigratedBuiltins_AreResolvedByProductionFactory()
public void Builtins_AreResolvedByProductionFactory()
{
Assert.IsType<DefaultPlateNester>(PlateNesterFactory.Create("Default"));
Assert.IsType<StripPlateNester>(PlateNesterFactory.Create("Strip"));
Assert.IsType<LegacyPlateNesterAdapter>(PlateNesterFactory.Create("Vertical Remnant"));
Assert.IsType<LegacyPlateNesterAdapter>(PlateNesterFactory.Create("Horizontal Remnant"));
Assert.IsType<RemnantPlateNester>(PlateNesterFactory.Create("Vertical Remnant"));
Assert.IsType<RemnantPlateNester>(PlateNesterFactory.Create("Horizontal Remnant"));
Assert.Throws<NotSupportedException>(() => PlateNesterFactory.Create("not registered"));
}
[Fact]
@@ -229,6 +190,55 @@ public class PlateNesterParityTests
);
}
[Fact]
public void DefaultRestrictedRotation_NeverTouchesFiller()
{
// Safety rule, not layout: any non-automatic rotation must bypass the Default fill
// pipeline entirely — its Pairs/RectBestFit strategies rotate freely and would propose
// forbidden poses. A throwing filler factory proves the filler is never constructed, and
// completion at the locked angle proves OrderedPlateNester handled the request.
var part = new NestJobPart(
"fixed",
PartGeometrySnapshot.FromProgram(TestDrawingFactory.Rectangle(6, 4)),
2,
rotation: RotationPolicy.Fixed(0)
);
var nester = new DefaultPlateNester(_ =>
throw new InvalidOperationException("filler must not run for restricted rotation")
);
var result = Solve(nester, Job(new[] { part }));
Assert.Equal(NestJobStatus.Complete, result.Status);
var placements = result.Plates.SelectMany(p => p.Placements).ToList();
Assert.Equal(2, placements.Count);
Assert.All(placements, p => Assert.True(AnglesEqual(p.Rotation, 0)));
}
[Fact]
public void RemnantRestrictedRotation_NeverTouchesFiller()
{
// Same safety rule for the remnant nester, whose fillers inherit the Default pipeline's
// automatic-rotation limitation. The throwing factory proves the filler is never
// constructed; completion at the locked angle proves OrderedPlateNester handled it.
var part = new NestJobPart(
"fixed",
PartGeometrySnapshot.FromProgram(TestDrawingFactory.Rectangle(6, 4)),
2,
rotation: RotationPolicy.Fixed(0)
);
var nester = new RemnantPlateNester(_ =>
throw new InvalidOperationException("filler must not run for restricted rotation")
);
var result = Solve(nester, Job(new[] { part }, strategy: "Vertical Remnant"));
Assert.Equal(NestJobStatus.Complete, result.Status);
var placements = result.Plates.SelectMany(p => p.Placements).ToList();
Assert.Equal(2, placements.Count);
Assert.All(placements, p => Assert.True(AnglesEqual(p.Rotation, 0)));
}
[Fact]
public void RepeatedNames_KeepIndependentIdentity()
{
@@ -294,9 +304,10 @@ public class PlateNesterParityTests
}
[Fact]
public void LegacyRemnantStrategies_StillResolveThroughAdapter()
public void DirectRemnantStrategies_FulfillThroughFactory()
{
// Remnant strategies must keep working through the legacy adapter after the factory change.
// Remnant strategies resolve to the direct remnant nester and still fulfill after the
// legacy adapter was deleted.
var part = new NestJobPart(
"p",
PartGeometrySnapshot.FromProgram(TestDrawingFactory.Rectangle(6, 4)),