mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-18 20:57:40 -05:00
fix(cutoffs): keep automatic lines clear of nearby cut-offs
Automatic cut-offs matched existing cut-offs only on the exact same line, so a grid line could land a hair beside a manual cut-off (or the planner's own tail separator) and cut a sliver strip next to it. The planner now keeps a cut clearance - the separator's part margin, the larger of part spacing and cut-off part clearance - from every parallel cut-off: - a full-span cut-off within it stands in for the proposed line (or the tail separator) and is certified at its own X; - a shortened or gapped manual cut within it is a blocking conflict, as an exact same-line conflict already was, and the shift search avoids it; - a strip line within it of a kept separator or full-span boundary is not cut, letting that strip run past the spacing by less than the clearance; the open sheet end keeps the bare tolerance, since oversize stock leaves its far edge unknown; - a new horizontal separator beside an unhonored horizontal cut-off is not proposed. With zero clearance and part spacing the guard falls back to the old same-line tolerance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
45e7d6f1c8
commit
cacfdcf5dc
5 files changed
+188
-22
No files matched your search
@@ -210,4 +210,19 @@ public class AutomaticCutOffHorizontalRemnantTests
|
||||
Assert.Contains(plan.Diagnostics, d => d.Code == AutomaticCutOffDiagnosticCode.NoSafeHorizontalSeparator);
|
||||
Assert.All(plan.Definitions, c => Assert.Equal(CutOffAxis.Vertical, c.Axis));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ManualCutBesideTheProposedLine_FallsBackToFullWidthStrips()
|
||||
{
|
||||
// The new separator would go at Y 21.3; a shortened manual line at 21.5 is inside the
|
||||
// 0.3 cut clearance, so a second line is not cut beside it.
|
||||
var plate = MakePlate(1);
|
||||
plate.CutOffs.Add(new CutOff(new Vector(0, 21.5), CutOffAxis.Horizontal) { EndLimit = 30 });
|
||||
|
||||
var plan = Plan(plate);
|
||||
|
||||
Assert.Null(plan.HorizontalSeparatorY);
|
||||
Assert.Contains(plan.Diagnostics, d => d.Code == AutomaticCutOffDiagnosticCode.NoSafeHorizontalSeparator);
|
||||
Assert.All(plan.Definitions, c => Assert.Equal(CutOffAxis.Vertical, c.Axis));
|
||||
}
|
||||
}
|
||||
@@ -742,12 +742,93 @@ public class AutomaticCutOffPlannerTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DifferentAxisOrDifferentCoordinate_DoesNotSuppress()
|
||||
public void DifferentAxisOrCoordinateBeyondClearance_DoesNotSuppress()
|
||||
{
|
||||
// The cut clearance is the 0.5 part spacing: a vertical line 0.6 away is a separate strip.
|
||||
var plate = MakePlate();
|
||||
plate.CutOffs.Add(new CutOff(new Vector(35, 35), CutOffAxis.Horizontal));
|
||||
plate.CutOffs.Add(new CutOff(new Vector(35.01, 0), CutOffAxis.Vertical));
|
||||
Assert.Equal(3, Plan(plate).Definitions.Count);
|
||||
plate.CutOffs.Add(new CutOff(new Vector(35.6, 0), CutOffAxis.Vertical));
|
||||
AssertPositions(new[] { 35, 70, 80.5 + Tolerance.Epsilon }, Plan(plate));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1, 35.01)]
|
||||
[InlineData(1, 34.6)]
|
||||
[InlineData(2, 35.01)]
|
||||
[InlineData(3, 34.6)]
|
||||
[InlineData(4, 35.01)]
|
||||
public void FullSpanCutOffBesideGridLine_StandsInForIt_InsteadOfASliver(int quadrant, double distance)
|
||||
{
|
||||
var plate = MakePlate(quadrant);
|
||||
var sign = quadrant is 2 or 3 ? -1 : 1;
|
||||
var manual = new CutOff(new Vector(sign * distance, 0), CutOffAxis.Vertical);
|
||||
plate.CutOffs.Add(manual);
|
||||
|
||||
var plan = Plan(plate);
|
||||
|
||||
Assert.False(plan.HasBlockingDiagnostics);
|
||||
AssertPositions(new[] { sign * 70, sign * (80.5 + Tolerance.Epsilon) }, plan);
|
||||
Assert.Contains(plan.Diagnostics, d => d.Code == AutomaticCutOffDiagnosticCode.ExistingCutOff && d.X == sign * 35);
|
||||
Assert.Same(manual, Assert.Single(plate.CutOffs));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LimitedCutOffBesideGridLine_BlocksWholePlan()
|
||||
{
|
||||
var plate = MakePlate();
|
||||
plate.CutOffs.Add(new CutOff(new Vector(35.3, 0), CutOffAxis.Vertical) { StartLimit = 10, EndLimit = 60 });
|
||||
|
||||
var plan = Plan(plate);
|
||||
|
||||
Assert.True(plan.HasBlockingDiagnostics);
|
||||
Assert.Empty(plan.Definitions);
|
||||
Assert.Contains(plan.Diagnostics, d => d.IsBlocking && d.X == 35 &&
|
||||
d.Code == AutomaticCutOffDiagnosticCode.LimitedCutOffConflict);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1)]
|
||||
[InlineData(2)]
|
||||
public void GridLineBesideTheSeparator_IsNotCut(int quadrant)
|
||||
{
|
||||
// Parts through 69.7 put the separator at 70.2: the grid line at 70 would leave a 0.2
|
||||
// sliver, so the last strip runs 35 to 70.2 instead.
|
||||
var plate = MakePlate(quadrant, occupied: 69.7);
|
||||
var sign = quadrant is 2 or 3 ? -1 : 1;
|
||||
|
||||
var plan = Plan(plate);
|
||||
|
||||
AssertPositions(new[] { sign * 35, sign * (70.2 + Tolerance.Epsilon) }, plan);
|
||||
Assert.True(plan.HasSeparatedTail);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GridLineBesideTheOpenSheetEnd_IsStillCut()
|
||||
{
|
||||
// Without a kept tail the strips run to the uncut sheet edge, so no clearance applies there.
|
||||
var plate = new Plate(81, 105.2) { PartSpacing = 0.5 };
|
||||
plate.Parts.Add(Rectangle(90, 20, new Vector(10, 20)));
|
||||
|
||||
var plan = AutomaticCutOffPlanner.Create(plate,
|
||||
new AutomaticCutOffOptions { Spacing = 35, MinimumTailLength = 12 }, new CutOffSettings());
|
||||
|
||||
AssertPositions(new[] { 35.0, 70, 105 }, plan);
|
||||
Assert.False(plan.HasSeparatedTail);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FullSpanCutOffBesideTheSeparator_IsTheSeparator()
|
||||
{
|
||||
var plate = MakePlate();
|
||||
plate.CutOffs.Add(new CutOff(new Vector(80.8, 0), CutOffAxis.Vertical));
|
||||
|
||||
var plan = Plan(plate);
|
||||
|
||||
AssertPositions(new[] { 35.0, 70 }, plan);
|
||||
Assert.True(plan.HasSeparatedTail);
|
||||
Assert.Equal(80.8, plan.TailSeparatorX);
|
||||
Assert.Equal(120 - 80.8, plan.TailLength, 9);
|
||||
Assert.Contains(plan.Diagnostics, d => d.Code == AutomaticCutOffDiagnosticCode.ExistingCutOff);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
||||
@@ -141,7 +141,7 @@ public class AutomaticCutOffShiftTests
|
||||
Assert.Equal(first.Diagnostics, second.Diagnostics);
|
||||
Assert.Equal(first.StripCutLength, second.StripCutLength);
|
||||
Assert.Equal(first.PreviewParts.Take(first.PreviewParts.Count - 1).Sum(p => CutLength(p.Program)), first.StripCutLength, 8);
|
||||
AssertLimits(first, 35, 17.5);
|
||||
AssertLimits(first, 35, 17.5, plate.PartSpacing + AutomaticCutOffPlanner.GeometryTolerance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,6 +212,30 @@ public class AutomaticCutOffShiftTests
|
||||
Assert.True(plan.StripCutLength < plan.FixedGridCutLength);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1)]
|
||||
[InlineData(2)]
|
||||
[InlineData(3)]
|
||||
[InlineData(4)]
|
||||
public void LimitedManualLine_BesideBestPosition_IsAvoidedByTheCutClearance(int quadrant)
|
||||
{
|
||||
var plate = UserCase(quadrant);
|
||||
var best = AutomaticCutOffPlanner.Create(plate, Options(), new CutOffSettings());
|
||||
var manualX = best.Definitions[0].Position.X + 0.2;
|
||||
plate.CutOffs.Add(new CutOff(new Vector(manualX, 0), CutOffAxis.Vertical)
|
||||
{
|
||||
EndLimit = plate.BoundingBox(false).Bottom + 2,
|
||||
});
|
||||
|
||||
var plan = AutomaticCutOffPlanner.Create(plate, Options(), new CutOffSettings());
|
||||
|
||||
Assert.False(plan.HasBlockingDiagnostics);
|
||||
Assert.Equal(3, plan.Definitions.Count);
|
||||
// The cut clearance is the 0.3 part spacing.
|
||||
Assert.All(plan.Definitions, c => Assert.True(System.Math.Abs(c.Position.X - manualX) >= 0.3,
|
||||
$"A line at {c.Position.X} sits beside the manual cut at {manualX}."));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1)]
|
||||
[InlineData(2)]
|
||||
@@ -345,7 +369,10 @@ public class AutomaticCutOffShiftTests
|
||||
var settings = new CutOffSettings();
|
||||
var fixedGrid = AutomaticCutOffPlanner.Create(plate,
|
||||
new AutomaticCutOffOptions { Spacing = 0.1 }, settings);
|
||||
Assert.Equal(1101, fixedGrid.Definitions.Count);
|
||||
// 1,099 strip lines through 109.9 and the separator just past 110.00009: the grid line
|
||||
// at 110 would sit 0.00009 from the separator, inside the 0.02 cut clearance, so it is
|
||||
// not cut.
|
||||
Assert.Equal(1100, fixedGrid.Definitions.Count);
|
||||
|
||||
var shifted = AutomaticCutOffPlanner.Create(plate,
|
||||
new AutomaticCutOffOptions { Spacing = 0.1, MinimumStripLength = 0.05 }, settings);
|
||||
@@ -354,7 +381,13 @@ public class AutomaticCutOffShiftTests
|
||||
Assert.True(shifted.StripCutLength <= shifted.FixedGridCutLength + 0.000001);
|
||||
}
|
||||
|
||||
internal static void AssertLimits(AutomaticCutOffPlan plan, double spacing, double minimum)
|
||||
/// <param name="cutClearance">
|
||||
/// The planner's cut clearance (the larger of part spacing and cut-off part clearance) when a
|
||||
/// test relies on it: the strip up to a kept separator is then never a sliver narrower than it,
|
||||
/// and may exceed the spacing by less than it instead.
|
||||
/// </param>
|
||||
internal static void AssertLimits(AutomaticCutOffPlan plan, double spacing, double minimum,
|
||||
double cutClearance = 0)
|
||||
{
|
||||
var positions = plan.Definitions.Where(c => c.Position.X != plan.TailSeparatorX)
|
||||
.Select(c => System.Math.Abs(c.Position.X)).ToArray();
|
||||
@@ -365,6 +398,10 @@ public class AutomaticCutOffShiftTests
|
||||
spacing + AutomaticCutOffPlanner.GeometryTolerance);
|
||||
previous = position;
|
||||
}
|
||||
Assert.InRange(plan.UsedSpan - previous, 0, spacing + AutomaticCutOffPlanner.GeometryTolerance);
|
||||
var allowance = System.Math.Max(cutClearance, AutomaticCutOffPlanner.GeometryTolerance);
|
||||
Assert.InRange(plan.UsedSpan - previous, 0, spacing + allowance);
|
||||
if (cutClearance > 0 && plan.HasSeparatedTail && positions.Length > 0)
|
||||
Assert.True(plan.UsedSpan - previous >= cutClearance - AutomaticCutOffPlanner.GeometryTolerance,
|
||||
$"A {plan.UsedSpan - previous}-wide sliver was left before the separator.");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user