Files
OpenNest/OpenNest.Engine.Tests/NestingEngines/RasterNestingEngineTests.cs
T
ajandClaude Sonnet 5.5 20323fda37 fix(engine): keep Raster parts inside the work area
Raster took each rotation's extents from the spacing outline, whose
vertices Clipper rounds to a 0.0001 grid, while the layout check measures
the geometry itself with 0.00001 of slack. A turned part pushed to a
work-area edge could end up to 0.00005 past it, which rejected seven of
the 49 variants on the README mixed job.

Position selection is unchanged. A part whose geometry would end past the
work area is nudged inside it, and a rotation whose geometry does not fit
the sheet is not tried, so already valid layouts stay identical.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 15:41:08 -05:00

95 lines
3.4 KiB
C#

using OpenNest.Clamps;
using OpenNest.Engine.Jobs;
using OpenNest.Engine.NestingEngines.Raster;
using OpenNest.Geometry;
using Xunit;
using static OpenNest.Engine.Tests.NestingEngines.JobBuilder;
using static OpenNest.Engine.Tests.NestingEngines.Shapes;
namespace OpenNest.Engine.Tests.NestingEngines;
public class RasterNestingEngineTests
{
[Theory]
[InlineData(0)]
[InlineData(0.02)]
[InlineData(0.25)]
[InlineData(1)]
public void MasksKeepTheSpacingWithoutRepair(double spacing)
{
// Arcs, notches and holes: every layout must pass the layout check as decoded.
var job = Job(
[
Part("ring", Ring(6, 3), 6),
Part("ell", LShape(9, 7, 3), 8),
Part("tri", Triangle(7, 7), 8),
Part("disc", Disc(1), 10),
],
[Stock("s", 24, 36, spacing)]);
var result = new RasterNestingEngine().Solve(job);
LayoutAssert.Valid(job, result);
Assert.Equal(NestJobStatus.Complete, result.Status);
}
[Theory]
[InlineData(1)]
[InlineData(3)]
[InlineData(5)]
[InlineData(7)]
public void TurnedPartsStayInsideTheWorkArea(int eighths)
{
// The turned extents have more decimals than the spacing outline's grid keeps, so a part
// pushed to a work-area edge by the outline's bounds can end up past it.
var job = Job(
[Part("tri", Polyline((0, 0), (7, 0), (0, 7)), 6, RotationPolicy.Fixed(eighths * System.Math.PI / 4))],
[Stock("s", 30, 40, 0.3, new Spacing(0.3, 0.3, 0.3, 0.3))]);
var result = new RasterNestingEngine().Solve(job);
LayoutAssert.Valid(job, result);
Assert.Equal(NestJobStatus.Complete, result.Status);
}
[Theory]
[InlineData(1)]
[InlineData(3)]
[InlineData(5)]
[InlineData(7)]
public void TurnedPartLargerThanTheSheetOnlyByItsGeometryStaysUnplaced(int eighths)
{
// The short extent is 4.949747: the outline's grid rounds it to the sheet's 4.9497.
var upright = eighths is 1 or 5;
var job = Job(
[Part("tri", Polyline((0, 0), (7, 0), (0, 7)), 1, RotationPolicy.Fixed(eighths * System.Math.PI / 4))],
[Stock("s", upright ? 4.9497 : 20, upright ? 20 : 4.9497, 0.3)]);
var result = new RasterNestingEngine().Solve(job);
LayoutAssert.Valid(job, result);
Assert.Empty(result.Plates);
}
[Fact]
public void SmallPartsNestInHoles()
{
// A 1 x 1 square fits a 10-wide ring's 8-wide hole; the sheet only holds the ring.
var job = Job([Part("ring", Ring(10, 8), 1), Part("square", Rectangle(1, 1), 4)],
[Stock("s", 10.2, 10.2, 0.1, quantity: 1)]);
var result = new RasterNestingEngine().Solve(job);
LayoutAssert.Valid(job, result);
Assert.Equal(NestJobStatus.Complete, result.Status);
}
[Fact]
public void ClampKeepOutsStayClear()
{
var job = Job([Part("ell", LShape(4, 3, 1), 20)],
[Stock("s", 20, 20, 0.2, clampZones: [new ClampZone("c", new Box(8, 0, 4, 2))])]);
var result = new RasterNestingEngine().Solve(job);
LayoutAssert.Valid(job, result);
Assert.Equal(NestJobStatus.Complete, result.Status);
}
[Fact]
public void IsRegistered() =>
Assert.IsType<RasterNestingEngine>(NestingEngineRegistry.Create("Raster"));
}
public sealed class RasterContractTests : EngineContractTests<RasterNestingEngine> { }