mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-16 21:45:34 -05:00
feat(cutting): route around tabbed parts before passing over them
A tabbed part stays in the sheet, so rapids were free to pass over it and the planner never looked for a way around. Plan Cutting now searches first with every tabbed outside as an obstacle once its part is cut. Where a pass stalls at a part whose approach crosses a tabbed part, only the crossed parts become crossable and the search goes on along the same order. A capture that search cannot plan is planned as before. Plates without tabbed outsides are searched once, unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
a84f8d1298
commit
92bf653c8f
9 files changed
+305
-16
No files matched your search
@@ -24,6 +24,25 @@ public sealed class ReleasedContourState
|
||||
private int partContours;
|
||||
private bool partClosed;
|
||||
|
||||
/// <summary>
|
||||
/// Parts (by caller part number) whose tabbed outside is an obstacle once the part ends, closed
|
||||
/// across its tab gap, as if the part were cut free. A tabbed part stays in the sheet and may be
|
||||
/// passed over, but a route around it is safer: planning looks for one first and lets rapids
|
||||
/// cross only the tabbed parts it finds no way around. It is asked at each rapid, so a part can
|
||||
/// become crossable after it was cut, in this state and its copies alike. Null avoids none.
|
||||
/// </summary>
|
||||
internal Func<int, bool> AvoidTabbedPart { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The part whose tabbed outside <paramref name="finding"/>'s rapid crosses, when that outside is
|
||||
/// an obstacle only because tabbed parts are avoided (<see cref="AvoidTabbedPart"/>); null otherwise.
|
||||
/// </summary>
|
||||
internal static int? AvoidedTabbedPart(PostVerificationFinding finding) =>
|
||||
finding is { Kind: PostVerificationKind.RapidCrossing, OtherPartNumber: { } part }
|
||||
&& finding.Message.EndsWith(TabbedOutside(part), StringComparison.Ordinal) ? part : null;
|
||||
|
||||
private static string TabbedOutside(int part) => $"the tabbed outside of part {part}.";
|
||||
|
||||
/// <summary>Why a lead-out after an open cut is refused when the open-cut proof cannot clear it.</summary>
|
||||
internal const string LeadOutRetentionMessage =
|
||||
"A lead-out follows an open cutting contour and may cut through its retention gap. "
|
||||
@@ -58,6 +77,7 @@ public sealed class ReleasedContourState
|
||||
{
|
||||
var copy = new ReleasedContourState(reportMissingLeadIns, tabMayNotHold, commonLineMember)
|
||||
{
|
||||
AvoidTabbedPart = AvoidTabbedPart,
|
||||
partContours = partContours,
|
||||
partClosed = partClosed,
|
||||
};
|
||||
@@ -229,6 +249,9 @@ public sealed class ReleasedContourState
|
||||
// A rapid well clear of a contour's extent can neither cross nor touch it.
|
||||
if (reach.IsClearOf(obstacle.Extent))
|
||||
continue;
|
||||
// A tabbed part is avoided only while planning still looks for a way around it.
|
||||
if (obstacle.Tabbed && AvoidTabbedPart?.Invoke(obstacle.Part) != true)
|
||||
continue;
|
||||
// A rapid leaving an overcut departs from its retraced tail, which lies on the first
|
||||
// cut only within the seam tolerance its arcs were matched at. Contact within that
|
||||
// much of the departure is the departure itself.
|
||||
@@ -244,6 +267,8 @@ public sealed class ReleasedContourState
|
||||
? $"the tabbed outside of part {obstacle.Part}, which its tab may not hold level."
|
||||
: obstacle.TabCutFree
|
||||
? $"the tabbed outside of part {obstacle.Part}, whose lead-out may cut its tab free."
|
||||
: obstacle.Tabbed
|
||||
? TabbedOutside(obstacle.Part)
|
||||
: $"completed untabbed contour {obstacle.Contour} of part {obstacle.Part}."))
|
||||
{
|
||||
Location = (start + move.End) * 0.5,
|
||||
@@ -391,13 +416,19 @@ public sealed class ReleasedContourState
|
||||
curves.Add(PostVerificationGeometry.Curve.Create(curves[^1].End, curves[0].Start, null, false));
|
||||
obstacles.Add(new(part, contourNumber, curves, null));
|
||||
}
|
||||
else if (!cutoff && unfinished.Count > 0 && (cutFree || tabMayNotHold?.Invoke(part) == true))
|
||||
else if (!cutoff && unfinished.Count > 0 && (cutFree || AvoidTabbedPart != null || tabMayNotHold?.Invoke(part) == true))
|
||||
{
|
||||
var perimeter = unfinished.MaxBy(chain => chain.Curves.Sum(curve => curve.Length));
|
||||
var curves = perimeter.Curves.ToList();
|
||||
if (curves[^1].End.DistanceTo(curves[0].Start) > PostVerificationGeometry.Epsilon)
|
||||
curves.Add(PostVerificationGeometry.Curve.Create(curves[^1].End, curves[0].Start, null, false));
|
||||
obstacles.Add(new(part, contourNumber, curves, null) { TabMayNotHold = !cutFree, TabCutFree = cutFree });
|
||||
var mayNotHold = !cutFree && tabMayNotHold?.Invoke(part) == true;
|
||||
obstacles.Add(new(part, contourNumber, curves, null)
|
||||
{
|
||||
TabMayNotHold = mayNotHold,
|
||||
TabCutFree = cutFree,
|
||||
Tabbed = !cutFree && !mayNotHold,
|
||||
});
|
||||
}
|
||||
partContours = contourNumber;
|
||||
partClosed = !cutoff && isFixed == null && unfinished.Count == 0 && deferred.Count == 0 && !reportedTab
|
||||
@@ -682,5 +713,8 @@ public sealed class ReleasedContourState
|
||||
|
||||
/// <summary>A tabbed perimeter closed across its tab gap, whose lead-out may cut the tab free.</summary>
|
||||
internal bool TabCutFree { get; init; }
|
||||
|
||||
/// <summary>A tabbed perimeter closed across its tab gap, avoided while another route exists.</summary>
|
||||
internal bool Tabbed { get; init; }
|
||||
}
|
||||
}
|
||||
@@ -265,9 +265,11 @@ public sealed class CuttingPlanBatch
|
||||
// A replayed proposal whose only warnings are fixed emissions passed every strict
|
||||
// check; fixed emissions never steer the search, so the full pass cannot improve it.
|
||||
// A plan keeping tab lead-outs is not taken from the short pass: the full pass may
|
||||
// still find a clean route.
|
||||
// still find a clean route. Nor is one that passes over tabbed parts: the full pass
|
||||
// may still find a route around them.
|
||||
if (first.IndependentlyReplayed && first.Status is CuttingPlanStatus.Ready or CuttingPlanStatus.BestEffort
|
||||
&& !first.Findings.Any(f => f.Kind == PostVerificationKind.TabLeadOut)
|
||||
&& (first.Snapshot is { AvoidsTabbedParts: true, CrossableTabbedParts.Count: 0 } || !snapshot.HasTabbedParts)
|
||||
|| first.Status == CuttingPlanStatus.Canceled)
|
||||
return first;
|
||||
}
|
||||
|
||||
@@ -91,10 +91,51 @@ public sealed class CuttingPlanSnapshot
|
||||
|
||||
/// <summary>
|
||||
/// An empty rapid checker for this capture. A tabbed part counts as steady once cut, so
|
||||
/// rapids may cross it as its retained material allows.
|
||||
/// rapids may cross it as its retained material allows; with <see cref="AvoidsTabbedParts"/>
|
||||
/// its outside is an obstacle all the same.
|
||||
/// </summary>
|
||||
internal ReleasedContourState NewReleasedState() =>
|
||||
new(reportMissingLeadIns: false, null, CommonLineMembers.Count == 0 ? null : CommonLineMembers.Contains);
|
||||
new(reportMissingLeadIns: false, null, CommonLineMembers.Count == 0 ? null : CommonLineMembers.Contains)
|
||||
{
|
||||
AvoidTabbedPart = AvoidsTabbedParts ? part => !CrossableTabbedParts.Contains(part) : null,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Whether rapids keep off tabbed parts already cut, as they do off parts cut free. Planning
|
||||
/// tries this first (<see cref="WithTabbedPartsAvoided"/>) and lets rapids cross only the
|
||||
/// tabbed parts it finds no way around (<see cref="CrossableTabbedParts"/>).
|
||||
/// </summary>
|
||||
internal bool AvoidsTabbedParts { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// With <see cref="AvoidsTabbedParts"/>, the part numbers (source ordinal + 1) of the tabbed
|
||||
/// parts rapids may still pass over. The one search planning this capture adds the parts it
|
||||
/// finds no route around (<see cref="AllowCrossing"/>); its checkers, cut-off placement and the
|
||||
/// replay of its plan all read this same set. Nothing else may change it.
|
||||
/// </summary>
|
||||
internal HashSet<int> CrossableTabbedParts { get; init; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Lets rapids pass over tabbed part <paramref name="partNumber"/> from here on. False when
|
||||
/// this capture does not avoid tabbed parts or the part was crossable already.
|
||||
/// </summary>
|
||||
internal bool AllowCrossing(int partNumber) => AvoidsTabbedParts && CrossableTabbedParts.Add(partNumber);
|
||||
|
||||
/// <summary>Whether any regenerated part's outside is tabbed, so avoiding tabbed parts changes the search.</summary>
|
||||
internal bool HasTabbedParts => Placements.Any(placement => placement.Prepared is { PerimeterTabbed: true });
|
||||
|
||||
/// <summary>The same capture planned with rapids kept off tabbed parts already cut.</summary>
|
||||
internal CuttingPlanSnapshot WithTabbedPartsAvoided() =>
|
||||
new(Placements, StartPoint, ExpansionBudget, Failure, Findings, Regeneration,
|
||||
PreservePartOrder, MaxEntries, ExpansionObserver, PlateState, OwnedParameters,
|
||||
Dependencies, BestEffort)
|
||||
{
|
||||
SupportTabsSkipped = SupportTabsSkipped,
|
||||
CommonLineMembers = CommonLineMembers,
|
||||
CommonLineOrder = CommonLineOrder,
|
||||
AcceptsTabLeadOuts = AcceptsTabLeadOuts,
|
||||
AvoidsTabbedParts = true,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Part numbers (source ordinal + 1) of the members of common-line groups cut once
|
||||
@@ -146,6 +187,8 @@ public sealed class CuttingPlanSnapshot
|
||||
CommonLineMembers = CommonLineMembers,
|
||||
CommonLineOrder = CommonLineOrder,
|
||||
AcceptsTabLeadOuts = AcceptsTabLeadOuts,
|
||||
AvoidsTabbedParts = AvoidsTabbedParts,
|
||||
CrossableTabbedParts = [.. CrossableTabbedParts],
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -162,6 +205,8 @@ public sealed class CuttingPlanSnapshot
|
||||
CommonLineMembers = CommonLineMembers,
|
||||
CommonLineOrder = CommonLineOrder,
|
||||
AcceptsTabLeadOuts = true,
|
||||
AvoidsTabbedParts = AvoidsTabbedParts,
|
||||
CrossableTabbedParts = [.. CrossableTabbedParts],
|
||||
};
|
||||
|
||||
/// <summary>Whether this capture accepts tab lead-outs (see <see cref="WithTabLeadOuts"/>).</summary>
|
||||
@@ -180,6 +225,8 @@ public sealed class CuttingPlanSnapshot
|
||||
CommonLineMembers = CommonLineMembers,
|
||||
CommonLineOrder = CommonLineOrder,
|
||||
AcceptsTabLeadOuts = AcceptsTabLeadOuts,
|
||||
AvoidsTabbedParts = AvoidsTabbedParts,
|
||||
CrossableTabbedParts = [.. CrossableTabbedParts],
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -290,6 +290,22 @@ public static class CuttingPlanService
|
||||
/// <summary>Worker-only planning uses owned values; live identities are never dereferenced.</summary>
|
||||
public static CuttingPlanResult Plan(CuttingPlanSnapshot snapshot, CancellationToken token = default)
|
||||
{
|
||||
// A tabbed part stays in the sheet and may be passed over, but a route around it is safer:
|
||||
// look for one first, with tabbed parts as obstacles, and cross them only without it.
|
||||
// Where the search finds no way around one, that part alone becomes crossable and the
|
||||
// search goes on, so a boxed-in part does not give up the rest. A plan it still cannot
|
||||
// find is searched for as before, with every tabbed part crossable.
|
||||
if (snapshot is { AvoidsTabbedParts: false, Regeneration: true, BestEffort: false, Failure: null, HasTabbedParts: true })
|
||||
{
|
||||
var avoiding = snapshot.WithTabbedPartsAvoided();
|
||||
var clear = PlanCaptured(avoiding, token);
|
||||
if (clear.IndependentlyReplayed && clear.Status is CuttingPlanStatus.Ready or CuttingPlanStatus.BestEffort
|
||||
|| clear.Status == CuttingPlanStatus.Canceled)
|
||||
{
|
||||
clear.Snapshot = avoiding;
|
||||
return clear;
|
||||
}
|
||||
}
|
||||
var result = PlanCaptured(snapshot, token);
|
||||
result.Snapshot = snapshot;
|
||||
// Refused only for configured lead-outs that may cut their tabs free: plan again keeping
|
||||
|
||||
@@ -94,16 +94,36 @@ internal static class JointCuttingPlanSearch
|
||||
if (snapshot.PreservePartOrder)
|
||||
{
|
||||
var keptSequence = Enumerable.Range(0, count).ToArray();
|
||||
if (preferEndpoints)
|
||||
// The order is fixed, so a tabbed part an approach cannot get around is passed over:
|
||||
// each pass that stops at one goes on from there with that part crossable.
|
||||
Node keptResume = null;
|
||||
while (true)
|
||||
{
|
||||
var preferred = walk.Follow(keptSequence, stall, null, preferredOnly: true);
|
||||
if (preferred.Order != null)
|
||||
return walk.Ready(preferred.Order);
|
||||
var recovered = walk.Follow(keptSequence, stall, null, contourRecovery: true);
|
||||
if (recovered.Order != null)
|
||||
return walk.Ready(recovered.Order);
|
||||
var stopped = new List<Attempt>();
|
||||
if (preferEndpoints)
|
||||
{
|
||||
var preferred = walk.Follow(keptSequence, stall, keptResume, preferredOnly: true);
|
||||
if (preferred.Order != null)
|
||||
return walk.Ready(preferred.Order);
|
||||
var recovered = walk.Follow(keptSequence, stall, keptResume, contourRecovery: true);
|
||||
if (recovered.Order != null)
|
||||
return walk.Ready(recovered.Order);
|
||||
stopped.AddRange([preferred, recovered]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The full pass below never stalls; this one only finds where a tabbed part blocks.
|
||||
var plain = snapshot.AvoidsTabbedParts ? walk.Follow(keptSequence, stall, keptResume) : null;
|
||||
if (plain?.Order != null)
|
||||
return walk.Ready(plain.Order);
|
||||
if (plain != null)
|
||||
stopped.Add(plain);
|
||||
}
|
||||
if (PassOver(snapshot, stopped) is not { } onward)
|
||||
break;
|
||||
keptResume = onward;
|
||||
}
|
||||
var kept = walk.Follow(keptSequence, null, null, expansionLimit: FallbackLimit());
|
||||
var kept = walk.Follow(keptSequence, null, keptResume, expansionLimit: FallbackLimit());
|
||||
return kept.Order != null ? walk.Ready(kept.Order) : walk.Exhausted();
|
||||
}
|
||||
|
||||
@@ -129,6 +149,7 @@ internal static class JointCuttingPlanSearch
|
||||
// A pass that teaches an order rule ends the round: the heavier passes would
|
||||
// only repeat the same blocked approach along the same order.
|
||||
Attempt attempt = null;
|
||||
Node onward = null;
|
||||
foreach (var (preferredOnly, contourRecovery) in preferEndpoints
|
||||
? new[] { (true, false), (false, true), (false, false) }
|
||||
: doorAlone ? [(false, true), (false, false)] : [(false, false)])
|
||||
@@ -136,12 +157,24 @@ internal static class JointCuttingPlanSearch
|
||||
var pass = walk.Follow(sequence, stall, resume, preferredOnly, contourRecovery, prerequisites);
|
||||
if (pass.Order != null)
|
||||
return walk.Ready(pass.Order);
|
||||
// Stopped at a tabbed part still avoided, after trying the entries that might
|
||||
// clear it: pass over it and go on from there along the same order. It teaches
|
||||
// no order rule, and the heavier passes are not tried first: on a plate of
|
||||
// tabbed parts either costs far more search than it saves crossings.
|
||||
onward = PassOver(snapshot, [pass]);
|
||||
if (onward != null)
|
||||
break;
|
||||
if (Learn(pass, sequence, prerequisites, revoked, swaps))
|
||||
{
|
||||
attempt = pass;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (onward != null)
|
||||
{
|
||||
resume = onward;
|
||||
continue;
|
||||
}
|
||||
// Nothing new to learn after a swap: take back the newest swap and learn the plain
|
||||
// rule its attempt would have taught instead, backing up from that attempt.
|
||||
while (attempt == null && swaps.Count != 0)
|
||||
@@ -232,6 +265,29 @@ internal static class JointCuttingPlanSearch
|
||||
}, token, exits);
|
||||
}
|
||||
|
||||
// Whether the pass stopped at a part whose approach crossed a tabbed part the capture still
|
||||
// avoids (see CuttingPlanSnapshot.AvoidsTabbedParts).
|
||||
private static bool StoppedAtTabbed(CuttingPlanSnapshot snapshot, Attempt pass) =>
|
||||
snapshot.AvoidsTabbedParts && pass.Blocked != null
|
||||
&& pass.CrossedTabbed.Any(part => !snapshot.CrossableTabbedParts.Contains(part + 1));
|
||||
|
||||
// Lets rapids pass over the tabbed parts still avoided that the heaviest of these stopped
|
||||
// passes crossed on its blocked approach. Returns the part boundary that pass was blocked at,
|
||||
// to go on from; null when no pass stopped at a tabbed part still avoided.
|
||||
private static Node PassOver(CuttingPlanSnapshot snapshot, IReadOnlyList<Attempt> stopped)
|
||||
{
|
||||
for (var index = stopped.Count - 1; index >= 0; index--)
|
||||
{
|
||||
var pass = stopped[index];
|
||||
if (!StoppedAtTabbed(snapshot, pass))
|
||||
continue;
|
||||
foreach (var part in pass.CrossedTabbed.Order())
|
||||
snapshot.AllowCrossing(part + 1);
|
||||
return pass.Boundary;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// When the approach crossed the part cut just before the one it left from, and no part but
|
||||
// those two, the tool went on past that part and came back across it: "cut those two the
|
||||
// other way round", so the tool leaves from the nearer one (two stacked strips, cut far one
|
||||
@@ -1791,6 +1847,15 @@ internal static class JointCuttingPlanSearch
|
||||
/// <summary>Parts whose completed contours the blocked part's motions crossed (it can be among them).</summary>
|
||||
internal HashSet<int> Crossed { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// The parts among <see cref="Crossed"/> whose tabbed outside was crossed while tabbed parts
|
||||
/// are avoided (<see cref="ReleasedContourState.AvoidedTabbedPart"/>).
|
||||
/// </summary>
|
||||
internal HashSet<int> CrossedTabbed { get; } = [];
|
||||
|
||||
/// <summary>The deepest whole-part boundary reached, where the blocked part's approach starts.</summary>
|
||||
internal Node Boundary => Deepest;
|
||||
|
||||
// Records a node that gets further along the order than any before. True when it does.
|
||||
internal bool Advance(Node node)
|
||||
{
|
||||
@@ -1802,6 +1867,7 @@ internal static class JointCuttingPlanSearch
|
||||
{
|
||||
Deepest = node;
|
||||
Crossed.Clear();
|
||||
CrossedTabbed.Clear();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1811,6 +1877,7 @@ internal static class JointCuttingPlanSearch
|
||||
progress = -1;
|
||||
Deepest = null;
|
||||
Crossed.Clear();
|
||||
CrossedTabbed.Clear();
|
||||
}
|
||||
|
||||
internal void NoteCrossings(int ordinal, IEnumerable<PostVerificationFinding> findings)
|
||||
@@ -1819,7 +1886,11 @@ internal static class JointCuttingPlanSearch
|
||||
return;
|
||||
foreach (var finding in findings)
|
||||
if (finding.Kind == PostVerificationKind.RapidCrossing && finding.OtherPartNumber is int other)
|
||||
{
|
||||
Crossed.Add(other - 1);
|
||||
if (ReleasedContourState.AvoidedTabbedPart(finding) != null)
|
||||
CrossedTabbed.Add(other - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The part boundary at <paramref name="depth"/> on the way to the deepest one.</summary>
|
||||
|
||||
@@ -44,7 +44,7 @@ public class PlanningCharacterizationTests
|
||||
[InlineData("holes-grid", "5410ECC55639AC89E49361D2D65E58C79FF940C65F5513F7E3A54EF04715BB25")]
|
||||
[InlineData("holes-grid-kept-order", "07B70B43549E95C65407B24944DA8F7262B784CFC4ABF86241C10DD8272B1780")]
|
||||
[InlineData("rounded-circle-leads", "73677429BFC950669D238E834CAE48F54A483759BE4E0BB1437D096F0AF7F3DA")]
|
||||
[InlineData("tabbed-perimeters", "6858C09A02D73E4531D0D59B6CD1CFFFA2C9C8BA5F48CF4943D9C4AEC17195BA")]
|
||||
[InlineData("tabbed-perimeters", "BE84012043FDCA472AFC8E5508CEB49D7A18F1FC964717D8F6938D46E412065F")]
|
||||
[InlineData("locked-among-regenerated", "42AFCF0DE942F501D8542C091C9D4407EAE41DE9442F75300348DCDB4FF0C733")]
|
||||
public void FocusedFixture_PlansExactlyAsBefore(string name, string expected)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
using OpenNest.CNC.CuttingPlanning;
|
||||
using OpenNest.CNC.CuttingStrategy;
|
||||
using OpenNest.Diagnostics;
|
||||
using OpenNest.Engine.CuttingPlanning;
|
||||
using OpenNest.Geometry;
|
||||
|
||||
namespace OpenNest.Tests.CuttingPlanning;
|
||||
|
||||
/// <summary>
|
||||
/// A tabbed part stays in the sheet, so a rapid may pass over it, but Plan Cutting looks for a
|
||||
/// route around it first and passes over only the tabbed parts it finds no way around.
|
||||
/// </summary>
|
||||
public class TabbedPartAvoidanceTests
|
||||
{
|
||||
private static CuttingParameters Tabbed()
|
||||
{
|
||||
var parameters = ExplicitContourTests.Parameters();
|
||||
parameters.TabsEnabled = true;
|
||||
parameters.TabConfig = new NormalTab { Size = 0.2 };
|
||||
return parameters;
|
||||
}
|
||||
|
||||
// The parts whose tabbed outside a rapid of the planned route passes over, by part number.
|
||||
private static int[] PassedOver(CuttingPlanResult result, Vector start)
|
||||
{
|
||||
var checker = new ReleasedContourState(reportMissingLeadIns: false) { AvoidTabbedPart = _ => true };
|
||||
var position = start;
|
||||
var crossed = new List<int>();
|
||||
foreach (var proposal in result.ProposedOrder)
|
||||
{
|
||||
var execution = ExecutionMotionReader.Read(proposal.CopyProgram(), proposal.Location, position, default);
|
||||
crossed.AddRange(checker.Check(execution, position, proposal.SourceOrdinal + 1)
|
||||
.Select(ReleasedContourState.AvoidedTabbedPart).OfType<int>());
|
||||
position = execution.DeparturePoint;
|
||||
}
|
||||
return crossed.Distinct().Order().ToArray();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TabbedParts_AreRoutedAround_WhenARouteExists()
|
||||
{
|
||||
// Four tabbed 10 x 10 squares in a 2 x 2 grid: left tabbed-crossable, the plan left each
|
||||
// square across the square itself.
|
||||
var plate = new Plate(300, 300);
|
||||
var square = new Drawing("square", ExplicitContourTests.Square(false));
|
||||
foreach (var i in Enumerable.Range(0, 4))
|
||||
plate.Parts.Add(new Part(square, new Vector(1 + i % 2 * 11, 1 + i / 2 * 11)));
|
||||
|
||||
var result = CuttingPlanService.Plan(CuttingPlanRequest.ForPlate(plate, new Vector(0, 0),
|
||||
confirmedParameters: Tabbed()));
|
||||
|
||||
Assert.True(result.Status == CuttingPlanStatus.Ready, string.Join("\n", result.Findings.Select(f => f.Message)));
|
||||
Assert.True(result.IndependentlyReplayed);
|
||||
Assert.Empty(PassedOver(result, new Vector(0, 0)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TabbedPart_IsPassedOver_OnlyWhereNoRouteGoesAround()
|
||||
{
|
||||
// A tabbed 0.8 x 10 upright strip between squares, in a kept order that goes left, strip,
|
||||
// right, then back left: that last rapid can only cross the strip.
|
||||
var plate = new Plate(20, 20);
|
||||
var square = new Drawing("square", LeadPathValidationTests.Rectangle(0, 0, 1, 1));
|
||||
plate.Parts.Add(new Part(square, new Vector(1, 2)));
|
||||
plate.Parts.Add(new Part(new Drawing("strip", LeadPathValidationTests.Rectangle(0, 0, 0.8, 10)), new Vector(4, 1)));
|
||||
plate.Parts.Add(new Part(square, new Vector(7, 4)));
|
||||
plate.Parts.Add(new Part(square, new Vector(1, 8)));
|
||||
|
||||
var result = CuttingPlanService.Plan(CuttingPlanRequest.ForPlate(plate, new Vector(0, 0),
|
||||
confirmedParameters: Tabbed(), preservePartOrder: true));
|
||||
|
||||
Assert.True(result.Status == CuttingPlanStatus.Ready, string.Join("\n", result.Findings.Select(f => f.Message)));
|
||||
Assert.True(result.IndependentlyReplayed);
|
||||
Assert.Equal([2], PassedOver(result, new Vector(0, 0)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithoutTabs_NothingIsAvoidedOrPassedOver()
|
||||
{
|
||||
var plate = new Plate(300, 300);
|
||||
var square = new Drawing("square", ExplicitContourTests.Square(false));
|
||||
foreach (var i in Enumerable.Range(0, 4))
|
||||
plate.Parts.Add(new Part(square, new Vector(1 + i % 2 * 11, 1 + i / 2 * 11)));
|
||||
|
||||
var snapshot = CuttingPlanService.Capture(CuttingPlanRequest.ForPlate(plate, new Vector(0, 0),
|
||||
confirmedParameters: ExplicitContourTests.Parameters()));
|
||||
var result = CuttingPlanService.Plan(snapshot);
|
||||
|
||||
Assert.Equal(CuttingPlanStatus.Ready, result.Status);
|
||||
Assert.False(snapshot.HasTabbedParts);
|
||||
Assert.False(result.Snapshot.AvoidsTabbedParts);
|
||||
}
|
||||
}
|
||||
+25
-1
@@ -39,7 +39,7 @@ var result = CuttingPlanService.Plan(snapshot, cancellationToken);
|
||||
the plate's own under `ForPlate`), each regenerated part the bed cannot hold level gets a
|
||||
tabbed perimeter whose automatic entries prefer points where the tab steadies it. A tabbed
|
||||
part counts as steady wherever its tab is: it is never warned about and stays crossable once
|
||||
cut. A tab in an inside corner is noted on the plan without changing its status. A part no
|
||||
cut, though the plan [goes around it where it can](#tabbed-parts-are-avoided-first). A tab in an inside corner is noted on the plan without changing its status. A part no
|
||||
longer than `TabHeldMaxLength` is held by its tab
|
||||
alone, so any tab clear of inside corners steadies it. Without a bed, or with
|
||||
`CuttingParameters.TabBySize`, the parts whose width is in `TabSizeMinWidth`..`TabSizeMaxWidth`
|
||||
@@ -294,6 +294,30 @@ expansion budget; exhausting it still returns a refusal from the service, never
|
||||
best-effort upgrade. Only the batch then looks for the separate
|
||||
[safest route](#safest-route-fallback-when-the-search-runs-out).
|
||||
|
||||
### Tabbed parts are avoided first
|
||||
|
||||
A tabbed part stays in the sheet, so a rapid may pass over it, but a route around it is safer.
|
||||
When any regenerated part's outside is tabbed (support tabs or the settings' own tabs),
|
||||
`CuttingPlanService.Plan` first searches with every tabbed outside as an obstacle once its part
|
||||
is cut, closed across its tab gap (`CuttingPlanSnapshot.WithTabbedPartsAvoided`,
|
||||
`ReleasedContourState.AvoidTabbedPart`). Entry backtracking then leaves a tabbed part on a
|
||||
side that clears it, where its catalog has one.
|
||||
|
||||
A pass along the order that stalls at a part whose approach crosses a tabbed part still avoided
|
||||
makes just the crossed parts crossable (`CuttingPlanSnapshot.CrossableTabbedParts`) and goes on
|
||||
from there along the same order. It learns no order rule from a tabbed part: on a plate of
|
||||
tabbed parts, reordering around each one spent the whole budget without finding a plan. So a
|
||||
tabbed part is passed over only where no entry of the parts on that order avoids it, typically
|
||||
a part whose only level-holding tab point faces away from the next cut. The checkers of that
|
||||
search, cut-off placement and the independent replay all read the same set, so the replayed
|
||||
plan is the one searched. Its hard obstacles are unchanged: a tabbed part's holes, parts cut
|
||||
free, and tabbed outsides whose lead-out may cut the tab free.
|
||||
|
||||
A capture this search cannot plan is planned again as before, with every tabbed part crossable.
|
||||
The desktop batch's short first pass is kept only when it passed over no tabbed part; otherwise
|
||||
the full pass looks for a route around them. The safest-route fallback and the pre-post review
|
||||
do not avoid tabbed parts. A plate with no tabbed outside is searched once, exactly as before.
|
||||
|
||||
### Cutoff segments
|
||||
|
||||
A cutoff segment is a fixed open cut that is cut the same way wherever it goes and is
|
||||
|
||||
@@ -184,7 +184,9 @@ its steadying entries.
|
||||
|
||||
A tabbed part counts as steady wherever its tab is: the steadiest entries above are preferences,
|
||||
never a warning. No message says a tab cannot steady its part, and once cut a tabbed part stays
|
||||
crossable, as its retained material allows, whether or not its tab holds it level. The pre-post
|
||||
crossable, as its retained material allows, whether or not its tab holds it level. Plan Cutting
|
||||
still routes around tabbed parts where it can and passes over only those it finds no way around
|
||||
(see [tabbed parts are avoided first](cutting-planner.md#tabbed-parts-are-avoided-first)). The pre-post
|
||||
review does not read support settings for rapids, so it checks rapid crossings against untabbed
|
||||
contours only.
|
||||
|
||||
|
||||
Reference in new issue
Block a user