fix(engine): prevent FillExtents overlap and add strategy filter API

FillExtents vertical copy distance was not clamped, allowing rows to be
placed overlapping each other when slide calculations returned large
values. Clamp to pairHeight + partSpacing minimum, matching FillLinear.

Also add FillStrategyRegistry.SetEnabled() to restrict which strategies
run — useful for isolating individual strategies during troubleshooting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-18 19:53:08 -04:00
parent c98e024f9c
commit 0a33047ad6
2 changed files with 20 additions and 11 deletions

View File

@@ -172,18 +172,12 @@ namespace OpenNest.Engine.Fill
if (minSlide >= double.MaxValue || minSlide < 0)
return pairHeight + partSpacing;
// Boundaries are inflated by halfSpacing, so when inflated edges touch
// the actual parts have partSpacing gap. Match FillLinear's pattern:
// startOffset = pairHeight (no extra spacing), copyDist = height - slide.
// Match FillLinear.ComputeCopyDistance: copyDist = startOffset - slide,
// clamped so it never goes below pairHeight + partSpacing to prevent
// bounding-box overlap from spurious slide values.
var copyDist = pairHeight - minSlide;
// Boundaries are inflated by halfSpacing, so the geometry-aware
// distance already guarantees partSpacing gap. Only fall back to
// bounding-box distance if the calculation produced a non-positive value.
if (copyDist <= Tolerance.Epsilon)
return pairHeight + partSpacing;
return copyDist;
return System.Math.Max(copyDist, pairHeight + partSpacing);
}
private static double SlideDistance(

View File

@@ -11,6 +11,7 @@ namespace OpenNest.Engine.Strategies
{
private static readonly List<IFillStrategy> strategies = new();
private static List<IFillStrategy> sorted;
private static HashSet<string> enabledFilter;
static FillStrategyRegistry()
{
@@ -18,7 +19,21 @@ namespace OpenNest.Engine.Strategies
}
public static IReadOnlyList<IFillStrategy> Strategies =>
sorted ??= strategies.OrderBy(s => s.Order).ToList();
sorted ??= (enabledFilter != null
? strategies.Where(s => enabledFilter.Contains(s.Name)).OrderBy(s => s.Order).ToList()
: strategies.OrderBy(s => s.Order).ToList());
/// <summary>
/// Restricts the active strategies to only those whose names are listed.
/// Pass null to restore all strategies.
/// </summary>
public static void SetEnabled(params string[] names)
{
enabledFilter = names != null && names.Length > 0
? new HashSet<string>(names, StringComparer.OrdinalIgnoreCase)
: null;
sorted = null;
}
public static void LoadFrom(Assembly assembly)
{