mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-04 15:19:25 -05:00
Expand Spacing widened gaps between parts but left each part's strip to the sheet edge at the plate's edge spacing, so past twice that spacing the edge strip became the thinnest web on the plate. A strip takes heat from one cut while a web between parts takes it from two, so each edge strip now holds at least half the spacing (never less than EdgeSpacing). The pair search pushes edge parts inward and only accepts a spacing whose strips hold. The pattern stretch sizes each axis's strips from the smallest gap that axis widens, so stretching along the rows before the rows open does not use up the edge room. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
98 lines
3.9 KiB
C#
98 lines
3.9 KiB
C#
using System.Collections.Generic;
|
|
using OpenNest.Clamps;
|
|
using OpenNest.CNC;
|
|
using OpenNest.Engine.Fill;
|
|
using OpenNest.Engine.Tests.Jobs;
|
|
using OpenNest.Geometry;
|
|
using Xunit;
|
|
|
|
namespace OpenNest.Engine.Tests.Fill;
|
|
|
|
public class ExpanderQualityReviewTests
|
|
{
|
|
private static Part AddSquare(Plate plate, double x, double y, double size)
|
|
{
|
|
var part = new Part(
|
|
new Drawing("neutral", TestDrawingFactory.Rectangle(size, size)), new Vector(x, y));
|
|
plate.Parts.Add(part);
|
|
return part;
|
|
}
|
|
|
|
private static Plate MakePlate(double length) =>
|
|
new(new Size(12, length)) { EdgeSpacing = new Spacing(0, 0) };
|
|
|
|
[Fact]
|
|
public void TinyZoneContainedInMover_MustNotReturnClearPositiveSpacing()
|
|
{
|
|
var plate = MakePlate(30);
|
|
plate.ClampZones.Add(new ClampZone("tiny", new Box(5, 5, 1e-5, 1e-5)));
|
|
var anchor = AddSquare(plate, 1, 4, 2);
|
|
var mover = AddSquare(plate, 4, 4, 2);
|
|
// Independent oracle: [5,5.00001]^2 lies strictly inside [4,6]^2.
|
|
var result = Expander.Expand(
|
|
new List<Part> { anchor, mover },
|
|
plate,
|
|
new Expander.Options { InitialStep = 3, MaxSpacing = 3 }
|
|
);
|
|
Assert.True(
|
|
result.Violations.Count > 0,
|
|
$"Physical clamp is still inside mover but report is clear: spacing={result.AchievedSpacing:R}, violations={result.Violations.Count}"
|
|
);
|
|
Assert.True(result.Violations[0].Achieved < 0);
|
|
}
|
|
|
|
[Fact]
|
|
public void TinyZoneInsideCutoutIsNotReportedAsMaterialOverlap()
|
|
{
|
|
// An edge spacing of half the target holds the frame's edge strips as is.
|
|
var plate = new Plate(new Size(12.5, 30.5)) { EdgeSpacing = new Spacing(0.25, 0.25) };
|
|
plate.ClampZones.Add(new ClampZone("tiny", new Box(5.25, 5.25, 1e-5, 1e-5)));
|
|
var frameProgram = TestDrawingFactory.Rectangle(10, 10);
|
|
frameProgram.MoveTo(4, 4);
|
|
frameProgram.LineTo(6, 4);
|
|
frameProgram.LineTo(6, 6);
|
|
frameProgram.LineTo(4, 6);
|
|
frameProgram.LineTo(4, 4);
|
|
var frame = new Part(new Drawing("neutral-frame", frameProgram), new Vector(0.25, 0.25));
|
|
plate.Parts.Add(frame);
|
|
|
|
var result = Expander.Separate(new List<Part> { frame }, plate, spacing: 0.5);
|
|
Assert.True(result.Converged, $"zone inside cutout reported as material: {result.Violations.Count}");
|
|
Assert.Empty(result.Violations);
|
|
Assert.Equal(0.25, frame.Location.X);
|
|
}
|
|
|
|
[Fact]
|
|
public void EdgeLimitedConvexOverlap_ShouldRetainCertifiedPartialImprovement()
|
|
{
|
|
// The anchor sits on the low edge, so only the mover can open the overlap.
|
|
var plate = MakePlate(6.5);
|
|
var anchor = AddSquare(plate, 0, 4, 4);
|
|
var mover = AddSquare(plate, 2, 4, 4);
|
|
var result = Expander.Expand(
|
|
new List<Part> { anchor, mover }, plate, new Expander.Options { MaxSpacing = 1 }
|
|
);
|
|
// Along x in [2,2.5], penetration is 4-x and strictly decreases.
|
|
Assert.True(
|
|
mover.Location.X >= 2.49,
|
|
$"Lost safe partial-overlap improvement: x={mover.Location.X:R}; expected edge at 2.5"
|
|
);
|
|
Assert.NotEmpty(result.Violations);
|
|
Assert.Equal(0, anchor.Location.X);
|
|
Assert.True(mover.Location.X + 4 <= 6.5 + 1e-9);
|
|
}
|
|
|
|
[Fact]
|
|
public void NegativeTarget_ConvexOverlapCanReachLessNegativeClearance()
|
|
{
|
|
var plate = MakePlate(30);
|
|
var anchor = AddSquare(plate, 5, 4, 4);
|
|
var mover = AddSquare(plate, 7, 4, 4);
|
|
var result = Expander.Separate(new List<Part> { anchor, mover }, plate, -1);
|
|
var opened = result.Positions[1].X - result.Positions[0].X;
|
|
Assert.True(result.Converged, $"Signed target -1 was not reached; opened={opened:R}");
|
|
Assert.True(opened >= 3 - 1e-6, $"opened={opened:R}");
|
|
Assert.Equal(7, mover.Location.X);
|
|
}
|
|
}
|