mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-14 04:35:07 -05:00
The best-fit filter rejected pairs over a 5:1 aspect (or the plate's) unless 75% utilized. A long part such as U251-DET3 (27.4 x 3.5, aspect 7.7) is past that alone, so its tightest interlocked pairs (5.1:1) were all dropped even though they are less elongated than the part itself. On the 60 x 120 sheet that cost 12 parts: 66 placed instead of 78. The limit now widens to the part's own bounding-box aspect, so side-by-side pairs survive while end-to-end pairs of compact parts are still rejected. The learned-angle characterization nests re-captured: their 46 x 3 bar now nests as an interlocked pair, which left the Fill nest identical to a full sweep, so the notched quantity drops from 6 to 4 to keep the fixture sensitive to learned angles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using OpenNest.Engine.BestFit;
|
|
using OpenNest.Shapes;
|
|
|
|
namespace OpenNest.Tests.BestFit;
|
|
|
|
public class BestFitFilterTests
|
|
{
|
|
// A 27.4 x 3.5 bar: aspect 7.8 on its own, past the default limit of 5.
|
|
private static Drawing MakeLongBar() =>
|
|
new RectangleShape { Width = 27.4, Length = 3.5 }.GetDrawing();
|
|
|
|
private static BestFitResult MakePair(Drawing drawing, double width, double height) =>
|
|
new()
|
|
{
|
|
Candidate = new PairCandidate { Drawing = drawing },
|
|
BoundingWidth = width,
|
|
BoundingHeight = height,
|
|
RotatedArea = width * height,
|
|
TrueArea = 0.5 * width * height,
|
|
Keep = true,
|
|
};
|
|
|
|
private static BestFitFilter MakeFilter() =>
|
|
BestFitFinder.CreateFilter(60, 120);
|
|
|
|
[Fact]
|
|
public void Apply_KeepsPairLessElongatedThanThePartAlone()
|
|
{
|
|
// Interlocked side by side, staggered lengthwise: aspect 5.1, under the part's own.
|
|
var pair = MakePair(MakeLongBar(), 5.7, 29.2);
|
|
|
|
MakeFilter().Apply([pair]);
|
|
|
|
Assert.True(pair.Keep, pair.Reason);
|
|
}
|
|
|
|
[Fact]
|
|
public void Apply_RejectsPairMoreElongatedThanThePartAlone()
|
|
{
|
|
// End to end: aspect 15.7, well past the part's own.
|
|
var pair = MakePair(MakeLongBar(), 3.5, 55);
|
|
|
|
MakeFilter().Apply([pair]);
|
|
|
|
Assert.False(pair.Keep);
|
|
Assert.StartsWith("Aspect ratio", pair.Reason);
|
|
}
|
|
|
|
[Fact]
|
|
public void Apply_CompactPartKeepsTheDefaultLimit()
|
|
{
|
|
var drawing = new RectangleShape { Width = 4, Length = 2 }.GetDrawing();
|
|
var pair = MakePair(drawing, 2, 11);
|
|
|
|
MakeFilter().Apply([pair]);
|
|
|
|
Assert.False(pair.Keep);
|
|
}
|
|
}
|