fix(planning): face the end a head-locked cut-off is cut from

A head-locked far-edge cut-off may be cut from either end, and the search
tries the nearer end first. The part cut just before it still aimed its exit
at the origin-side start, so a ring beside the far edge left from its bottom
and the rapid back up to the far-edge start crossed the ring just cut. N26-2EU
(four flange rings beside a scrap cut-off) planned UNVERIFIED with two rapid
crossings. The part now faces whichever start is nearer to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-12-02 09:47:13 -05:00
1 parent 9b4de5a385
commit 0a2b1c64cf
2 files changed
+93

No files matched your search

@@ -691,6 +691,8 @@ internal static class JointCuttingPlanSearch
// nearest of the host's own contours instead.
private Vector Facing(FixedProgramPlacement source, FixedProgramPlacement next)
{
if (next.IsCutOff && !source.IsCutOff)
return CutOffArrival(source, next);
if (source.IsCutOff || next.IsCutOff
|| !snapshot.Dependencies.PrerequisitesOf(next.SourceOrdinal).Contains(source.SourceOrdinal))
return Center(next);
@@ -703,6 +705,20 @@ internal static class JointCuttingPlanSearch
: contours.Select(c => c.ClosestPointTo(from)).MinBy(point => point.DistanceTo(from));
}
// A cut-off is entered at its start. A head-locked far-edge segment may be cut from either
// end and the search tries the nearer first, so the part before it faces that end: facing
// the origin-side start from beside the far edge leaves the part on the wrong side, and
// the rapid back to the far edge then runs over the part just cut.
private static Vector CutOffArrival(FixedProgramPlacement source, FixedProgramPlacement cutOff)
{
var start = Center(cutOff);
if (cutOff.Reversed is not { } reversed)
return start;
var from = Center(source);
var reversedStart = Center(reversed);
return reversedStart.DistanceTo(from) < start.DistanceTo(from) ? reversedStart : start;
}
/// <summary>
/// Nearest-first BETWEEN source parts (fallback search keeps its tour), but inside
/// one part and contour stage the automatic rank leads — OrderBy(Distance) alone
@@ -110,6 +110,83 @@ public class HeadLockedCutOffPlanningTests
Assert.False(CutOff.StartsAtFarEdge(Assert.Single(plate.Parts).Program));
}
// A production nest: four flange rings in two staggered columns, the right column one part spacing short
// of a head-locked scrap cut-off that separates the sheet. Only the top right ring, cut last,
// reaches the cut-off, and only its far-edge end: its origin-side start lies below the other
// right-column ring. The ring before the cut-off must face that far end; facing the origin-side
// start left it at its bottom, and the rapid back up to the far edge ran over the ring just cut.
[Fact]
public void Plan_PartBeforeAHeadLockedSeparator_FacesTheFarEdgeEndItIsCutFrom()
{
var plate = new Plate(new Size(48, 96))
{
PartSpacing = 0.25,
EdgeSpacing = new Spacing(0.25, 0.25),
SupportBed = new OpenNest.Support.SupportGrid(2, 2, registrationTolerance: 0.125, stabilityMargin: 0.25),
};
var small = Flange("flange-a", -0.1169055982, 5.40625, 1.34375);
var large = Flange("flange-b", -0.5231555982, 5, 1.75);
plate.Parts.Add(new Part(small, new Vector(7.218867531118205, 13.131029095041303)));
plate.Parts.Add(new Part(small, new Vector(15.315900000000006, 24.262600000000003)));
plate.Parts.Add(new Part(large, new Vector(7.218867531118205, 35.394200000000005)));
plate.Parts.Add(new Part(large, new Vector(15.315900000000006, 46.525800000000004)));
var settings = new CutOffSettings { Overtravel = 0.75, MinSegmentLength = 1, LockHeadHeight = true, HeadLockOvercut = 0.25 };
var staged = AutomaticCutOffBatch.Stage([plate], new AutomaticCutOffOptions
{
Spacing = 35,
MinimumStripLength = 17.5,
MinimumTailLength = 12,
KeepHorizontalRemnant = true,
}, settings);
var cutOff = Assert.Single(Assert.Single(staged.Plans).Definitions);
Assert.Equal(CutOffAxis.Vertical, cutOff.Axis);
var result = CuttingPlanService.Plan(CuttingPlanRequest.ForPlate(plate, confirmedParameters: FlangeParameters(),
preservePartOrder: true));
Assert.True(result.Status == CuttingPlanStatus.Ready && result.IndependentlyReplayed, Describe(result));
var last = result.ProposedOrder[^1];
Assert.True(last.IsCutOff && last.ReversesCutOff);
Assert.Same(plate.Parts[3], result.ProposedOrder[^2].SourcePart);
}
// Six bolt holes on a 6.125 circle, the bore, then the 13.5 OD: the drawing as saved.
private static Drawing Flange(string name, double toBore, double boreRadius, double toOutside) =>
new(name, new OpenNest.IO.ProgramReader(new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(string.Create(System.Globalization.CultureInfo.InvariantCulture, $"""
G91
G00X0Y0
G03X0Y0I-0.21875J0
G00X5.3044055982Y-3.0625
G03X0Y0I-0.21875J0
G00X-5.3044055982Y-9.1875
G03X0Y0I-0.21875J0
G00X-5.3044055982Y3.0625
G03X0Y0I-0.21875J0
G00X0Y6.125
G03X0Y0I-0.21875J0
G00X10.6088111964Y-6.125
G03X0Y0I-0.21875J0
G00X{toBore}Y3.0625
G03X0Y0I-{boreRadius}J0
G00X{toOutside}Y0
G02X0Y0I-6.75J0
""")))).Read());
// The CI Fiber 4020's 3/16 stainless settings the nest was planned with.
private static OpenNest.CNC.CuttingStrategy.CuttingParameters FlangeParameters() => new()
{
Kerf = 0.01,
ExternalLeadIn = new OpenNest.CNC.CuttingStrategy.LineLeadIn { Length = 0.15, ApproachAngle = 60 },
ExternalLeadOut = new OpenNest.CNC.CuttingStrategy.LineLeadOut { Length = 0.1, ApproachAngle = 60 },
InternalLeadIn = new OpenNest.CNC.CuttingStrategy.LineLeadIn { Length = 0.15, ApproachAngle = 60 },
InternalLeadOut = new OpenNest.CNC.CuttingStrategy.NoLeadOut(),
PierceClearance = 0.0625,
PierceDiameter = 0.03,
SupportTabs = true,
TabSizeMaxWidth = 12,
SliceTippingSlugs = true,
};
private static readonly OpenNest.CNC.CuttingStrategy.CuttingParameters Parameters = ExplicitContourTests.Parameters();
private static (Plate Plate, CutOff CutOff) SingleLine(double headLock)