Files
OpenNest/OpenNest.Tests/CuttingPlanning/SlenderPartOrderTests.cs
T
ajandClaude Opus 5.5 1bfa9622b7 fix(cutting): order locked and slender holed parts by where they are cut
Plan Cutting ordered whole parts by their centers. On N26-2DJ a 15.8"
terminal stands upright beside a stack of the same part, pierced at its
top end; its center sits halfway up the stack, so the tour cut it 7th
instead of 13th and added 11.3" of rapid (40.9" to 52.2").

A program kept as given (a locked part) now enters the tour at its first
cut and leaves from its departure, as cut-offs already did. A slender
regenerated part with holes (extent at least 3:1) is reached and left at
whichever hole center suits its neighbors, since its holes are cut first
and its outside entry leaves beside them; after the center tour it moves
to the gap where that detour is shortest. Hole-less parts keep their
centers: their entry faces whatever comes next.

N26-2DJ now plans to 40.8" locked and 39.6" unlocked. The
locked-among-regenerated digest changes only in expansions (268 to 55);
its order and rapids are unchanged. The part-order corpus meets every
baseline and no plate nears its budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 11:25:51 -05:00

90 lines
4.0 KiB
C#

using OpenNest.CNC;
using OpenNest.CNC.CuttingPlanning;
using OpenNest.CNC.CuttingStrategy;
using OpenNest.Engine.CuttingPlanning;
using OpenNest.Geometry;
namespace OpenNest.Tests.CuttingPlanning;
/// <summary>
/// A long strip standing beside a stack of rows (N26-2DJ: one terminal turned upright beside the
/// others) is cut where the tool reaches it, its top end, not where its center sits halfway up.
/// </summary>
public class SlenderPartOrderTests
{
private const int Rows = 16;
[Fact]
public void LockedStrip_IsCutBesideTheRowsNearItsPierce()
{
var parameters = ExplicitContourTests.Parameters();
var parts = Stack(parameters);
var strip = Strip(parameters, LeadPathValidationTests.Rectangle(0, 0, 1, 14));
strip.LeadInsLocked = true;
parts.Add(strip);
var position = PositionOf(strip, parts, parameters);
// Its pierce is at its top, beside rows 8 and 9. Ordered by its center, beside rows 4
// and 5, it was cut sixth.
Assert.True(position is >= 8 and <= 10, $"strip cut at position {position}");
}
[Fact]
public void StripWithAHoleAtItsTop_IsCutBesideTheRowsNearTheHole()
{
var parameters = ExplicitContourTests.Parameters();
var parts = Stack(parameters);
var drawing = LeadPathValidationTests.Rectangle(0, 0, 1, 14);
drawing.MoveTo(0.75, 13.5); drawing.ArcTo(0.75, 13.5, 0.5, 13.5, RotationType.CCW);
var strip = Strip(parameters, drawing);
parts.Add(strip);
var position = PositionOf(strip, parts, parameters);
// Its hole is cut first and its outside entry leaves beside it, at its top. Ordered by its
// center, it was cut last.
Assert.True(position is >= 8 and <= 10, $"strip cut at position {position}");
}
private static int PositionOf(Part strip, List<Part> parts, CuttingParameters parameters)
{
var result = CuttingPlanService.Plan(new CuttingPlanRequest(parts, confirmedParameters: parameters));
Assert.True(result.ProposedOrder.Count != 0, $"{result.Status}: {string.Join("; ", result.Findings.Select(f => f.Message))}");
return result.ProposedOrder.Select(p => p.SourcePart).ToList().IndexOf(strip);
}
// Sixteen 16 x 1 rows, 1.5 apart, from y 0.5, each with a hole at its right end like the
// terminals: the stack runs on well past the strip's top.
private static List<Part> Stack(CuttingParameters parameters) =>
Enumerable.Range(0, Rows).Select(row =>
{
var clean = LeadPathValidationTests.Rectangle(0, 0, 16, 1);
clean.MoveTo(15.75, 0.5); clean.ArcTo(15.75, 0.5, 15.5, 0.5, RotationType.CCW);
var part = new Part(new Drawing($"row {row}", clean), new Vector(0, 0.5 + 1.5 * row));
var prepared = PreparedContours.Capture(clean, parameters);
var choices = Enumerable.Range(0, prepared.Count)
.Select(contour => prepared.ClosestEntry(contour, contour == prepared.PerimeterOrdinal
? new Vector(17, 0.5) : new Vector(15.75, 0.5)))
.ToArray();
Assert.True(part.RestoreLeadInProgram(prepared.Emit(choices), false));
part.CuttingParameters = parameters;
return part;
}).ToList();
// A 1 x 14 strip standing beside the rows, entered at its top edge.
private static Part Strip(CuttingParameters parameters, Program clean)
{
var part = new Part(new Drawing("strip", clean), new Vector(17, 0.5));
var prepared = PreparedContours.Capture(clean, parameters);
var choices = Enumerable.Range(0, prepared.Count)
.Select(contour => contour == prepared.PerimeterOrdinal
? prepared.ClosestEntry(contour, new Vector(0.5, 15))
: prepared.ClosestEntry(contour, new Vector(0.75, 13.5)))
.ToArray();
Assert.True(part.RestoreLeadInProgram(prepared.Emit(choices), false));
part.CuttingParameters = parameters;
return part;
}
}