Files
OpenNest/OpenNest.Engine.Tests/Fill/ShrinkWorkAreaTests.cs
T
aj 365825bc5a fix(engine): shrink the requested axis in ShrinkFiller estimates
ShrinkAxis.Length must shrink the Y extent and ShrinkAxis.Width the X
extent to agree with MeasureDimension/TrimToCount; Box's constructor
takes the X extent first. The estimate previously shrank the wrong
dimension and returned a mis-ordered box. Add a parameterized regression
test over both axes and both translated-remnant orientations.
2026-09-21 10:05:18 -04:00

41 lines
1.4 KiB
C#

using OpenNest.Engine.Fill;
using OpenNest.Engine.Tests.Jobs;
using OpenNest.Geometry;
namespace OpenNest.Engine.Tests.Fill;
public class ShrinkWorkAreaTests
{
[Theory]
[InlineData(ShrinkAxis.Length, 30, 60)]
[InlineData(ShrinkAxis.Length, 60, 30)]
[InlineData(ShrinkAxis.Width, 30, 60)]
[InlineData(ShrinkAxis.Width, 60, 30)]
public void EstimateStartBox_ShrinksOnlyRequestedAxis_WithinTranslatedRectangularRemnant(
ShrinkAxis axis, double length, double width)
{
var item = new NestItem
{
Drawing = new Drawing("rectangle", TestDrawingFactory.Rectangle(4, 3)),
Quantity = 2,
};
var box = new Box(80, 7, length, width);
var estimate = ShrinkFiller.EstimateStartBox(item, box, 0.3, axis, 2);
Assert.Equal(box.Location, estimate.Location);
Assert.True(box.Contains(estimate), "A shrink estimate must never expand beyond its input remnant.");
// ShrinkAxis follows the fill/trim direction: Length trims top, Width trims right.
if (axis == ShrinkAxis.Length)
{
Assert.Equal(box.Length, estimate.Length);
Assert.InRange(estimate.Width, double.Epsilon, box.Width - double.Epsilon);
}
else
{
Assert.Equal(box.Width, estimate.Width);
Assert.InRange(estimate.Length, double.Epsilon, box.Length - double.Epsilon);
}
}
}