feat: add VerticalRemnantEngine and HorizontalRemnantEngine

Two new engine classes subclassing DefaultNestEngine that override
CreateComparer, PreferredDirection, and BuildAngles to optimize for
preserving side remnants. Both registered in NestEngineRegistry and
covered by 6 integration tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-21 12:57:33 -04:00
parent 83124eb38d
commit 0b7697e9c0
4 changed files with 184 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using OpenNest.Engine;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest
{
/// <summary>
/// Optimizes for the largest top-side horizontal drop.
/// Scores by count first, then minimizes Y-extent.
/// Prefers vertical nest direction and angles that keep parts narrow in Y.
/// </summary>
public class HorizontalRemnantEngine : DefaultNestEngine
{
public HorizontalRemnantEngine(Plate plate) : base(plate) { }
public override string Name => "Horizontal Remnant";
public override string Description => "Optimizes for largest top-side horizontal drop";
protected override IFillComparer CreateComparer() => new HorizontalRemnantComparer();
public override NestDirection? PreferredDirection => NestDirection.Vertical;
public override List<double> BuildAngles(NestItem item, double bestRotation, Box workArea)
{
var baseAngles = new List<double> { bestRotation, bestRotation + Angle.HalfPI };
baseAngles.Sort((a, b) => RotatedHeight(item, a).CompareTo(RotatedHeight(item, b)));
return baseAngles;
}
private static double RotatedHeight(NestItem item, double angle)
{
var bb = item.Drawing.Program.BoundingBox();
var cos = System.Math.Abs(System.Math.Cos(angle));
var sin = System.Math.Abs(System.Math.Sin(angle));
return bb.Length * cos + bb.Width * sin;
}
}
}

View File

@@ -24,6 +24,14 @@ namespace OpenNest
Register("NFP",
"NFP-based mixed-part nesting with simulated annealing",
plate => new NfpNestEngine(plate));
Register("Vertical Remnant",
"Optimizes for largest right-side vertical drop",
plate => new VerticalRemnantEngine(plate));
Register("Horizontal Remnant",
"Optimizes for largest top-side horizontal drop",
plate => new HorizontalRemnantEngine(plate));
}
public static IReadOnlyList<NestEngineInfo> AvailableEngines => engines;

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using OpenNest.Engine;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest
{
/// <summary>
/// Optimizes for the largest right-side vertical drop.
/// Scores by count first, then minimizes X-extent.
/// Prefers horizontal nest direction and angles that keep parts narrow in X.
/// </summary>
public class VerticalRemnantEngine : DefaultNestEngine
{
public VerticalRemnantEngine(Plate plate) : base(plate) { }
public override string Name => "Vertical Remnant";
public override string Description => "Optimizes for largest right-side vertical drop";
protected override IFillComparer CreateComparer() => new VerticalRemnantComparer();
public override NestDirection? PreferredDirection => NestDirection.Horizontal;
public override List<double> BuildAngles(NestItem item, double bestRotation, Box workArea)
{
var baseAngles = new List<double> { bestRotation, bestRotation + Angle.HalfPI };
baseAngles.Sort((a, b) => RotatedWidth(item, a).CompareTo(RotatedWidth(item, b)));
return baseAngles;
}
private static double RotatedWidth(NestItem item, double angle)
{
var bb = item.Drawing.Program.BoundingBox();
var cos = System.Math.Abs(System.Math.Cos(angle));
var sin = System.Math.Abs(System.Math.Sin(angle));
return bb.Width * cos + bb.Length * sin;
}
}
}