refactor(engine): move fill and strategy code to dedicated namespaces

Move fill algorithms to OpenNest.Engine.Fill namespace:
FillLinear, FillExtents, PairFiller, ShrinkFiller, Compactor,
RemnantFiller, RemnantFinder, FillScore, Pattern, PatternTiler,
PartBoundary, RotationAnalysis, AngleCandidateBuilder, and
AccumulatingProgress.

Move strategy layer to OpenNest.Engine.Strategies namespace:
IFillStrategy, FillContext, FillStrategyRegistry, FillHelpers,
and all built-in strategy implementations.

Add using directives to all consuming files across Engine, UI,
MCP, and Tests projects.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-18 16:46:11 -04:00
parent 0cba528591
commit 0e1e619f0a
44 changed files with 141 additions and 119 deletions

View File

@@ -1,9 +1,10 @@
using OpenNest.Converters;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using OpenNest.Converters;
using OpenNest.Geometry;
namespace OpenNest.Engine.BestFit
{

View File

@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
/// <summary>
/// Wraps an IProgress to prepend previously placed parts to each report,

View File

@@ -1,11 +1,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using OpenNest.Engine.ML;
using OpenNest.Geometry;
using OpenNest.Math;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
/// <summary>
/// Builds candidate rotation angles for single-item fill. Encapsulates the

View File

@@ -1,9 +1,8 @@
using System;
using OpenNest.Geometry;
using System.Collections.Generic;
using System.Linq;
using OpenNest.Geometry;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
/// <summary>
/// Pushes a group of parts left and down to close gaps after placement.

View File

@@ -1,11 +1,11 @@
using OpenNest.Geometry;
using OpenNest.Math;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
public class FillExtents
{

View File

@@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using OpenNest.Geometry;
using OpenNest.Math;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
public class FillLinear
{
@@ -16,7 +16,7 @@ namespace OpenNest
public Box WorkArea { get; }
public double PartSpacing { get; }
public double HalfSpacing => PartSpacing / 2;
/// <summary>

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic;
using OpenNest.Geometry;
using System.Collections.Generic;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
public readonly struct FillScore : System.IComparable<FillScore>
{

View File

@@ -1,13 +1,14 @@
using OpenNest.Engine.BestFit;
using OpenNest.Engine.Strategies;
using OpenNest.Geometry;
using OpenNest.Math;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using OpenNest.Engine.BestFit;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
/// <summary>
/// Fills a work area using interlocking part pairs from BestFitCache.
@@ -52,11 +53,11 @@ namespace OpenNest
var engine = new FillLinear(workArea, partSpacing);
// Let the remainder strip try pair-based filling too.
var p0 = DefaultNestEngine.BuildRotatedPattern(pairParts, 0);
var p90 = DefaultNestEngine.BuildRotatedPattern(pairParts, Angle.HalfPI);
var p0 = FillHelpers.BuildRotatedPattern(pairParts, 0);
var p90 = FillHelpers.BuildRotatedPattern(pairParts, Angle.HalfPI);
engine.RemainderPatterns = new List<Pattern> { p0, p90 };
var filled = DefaultNestEngine.FillPattern(engine, pairParts, angles, workArea);
var filled = FillHelpers.FillPattern(engine, pairParts, angles, workArea);
if (filled != null && filled.Count > 0)
{

View File

@@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using OpenNest.Converters;
using OpenNest.Geometry;
using System.Collections.Generic;
using System.Linq;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
/// <summary>
/// Pre-computed offset boundary polygons for a part's geometry.
@@ -87,9 +87,9 @@ namespace OpenNest
var edge = (verts[i - 1], verts[i]);
if (-sign * dy > 0) left.Add(edge);
if ( sign * dy > 0) right.Add(edge);
if (sign * dy > 0) right.Add(edge);
if (-sign * dx > 0) up.Add(edge);
if ( sign * dx > 0) down.Add(edge);
if (sign * dx > 0) down.Add(edge);
}
}
@@ -145,11 +145,11 @@ namespace OpenNest
{
switch (direction)
{
case PushDirection.Left: return _leftEdges;
case PushDirection.Left: return _leftEdges;
case PushDirection.Right: return _rightEdges;
case PushDirection.Up: return _upEdges;
case PushDirection.Down: return _downEdges;
default: return _leftEdges;
case PushDirection.Up: return _upEdges;
case PushDirection.Down: return _downEdges;
default: return _leftEdges;
}
}

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic;
using OpenNest.Geometry;
using System.Collections.Generic;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
public class Pattern
{

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic;
using OpenNest.Geometry;
using System.Collections.Generic;
namespace OpenNest.Engine
namespace OpenNest.Engine.Fill
{
public static class PatternTiler
{

View File

@@ -1,9 +1,9 @@
using OpenNest.Geometry;
using System;
using System.Collections.Generic;
using System.Threading;
using OpenNest.Geometry;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
/// <summary>
/// Iteratively fills remnant boxes with items using a RemnantFinder.

View File

@@ -1,9 +1,8 @@
using System;
using OpenNest.Geometry;
using System.Collections.Generic;
using System.Linq;
using OpenNest.Geometry;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
/// <summary>
/// A remnant box with a priority tier.

View File

@@ -1,10 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using OpenNest.Converters;
using OpenNest.Geometry;
using OpenNest.Math;
using System.Collections.Generic;
using System.Linq;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
internal static class RotationAnalysis
{

View File

@@ -1,10 +1,10 @@
using OpenNest.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using OpenNest.Geometry;
namespace OpenNest
namespace OpenNest.Engine.Fill
{
public enum ShrinkAxis { Width, Height }

View File

@@ -1,9 +1,10 @@
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using OpenNest.Geometry;
namespace OpenNest
{
@@ -212,9 +213,13 @@ namespace OpenNest
$"PartArea={totalPartArea:F0}, Remnant={workArea.Area() - totalPartArea:F0}, " +
$"WorkArea={workArea.Width:F1}x{workArea.Length:F1} | {description}";
Debug.WriteLine(msg);
try { System.IO.File.AppendAllText(
try
{
System.IO.File.AppendAllText(
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "nest-debug.log"),
$"{DateTime.Now:HH:mm:ss.fff} {msg}\n"); } catch { }
$"{DateTime.Now:HH:mm:ss.fff} {msg}\n");
}
catch { }
progress.Report(new NestProgress
{

View File

@@ -1,6 +1,5 @@
using System;
using OpenNest.Geometry;
using OpenNest.Math;
using OpenNest.Math;
using System;
namespace OpenNest.RectanglePacking
{

View File

@@ -1,8 +1,8 @@
using System.Collections.Generic;
using OpenNest.Engine.BestFit;
using OpenNest.Engine.Fill;
using OpenNest.Math;
using System.Collections.Generic;
namespace OpenNest
namespace OpenNest.Engine.Strategies
{
public class ExtentsFillStrategy : IFillStrategy
{
@@ -20,10 +20,6 @@ namespace OpenNest
var angles = new[] { bestRotation, bestRotation + Angle.HalfPI };
var bestFits = context.SharedState.TryGetValue("BestFits", out var cached)
? (List<BestFitResult>)cached
: null;
List<Part> best = null;
var bestScore = default(FillScore);
@@ -31,7 +27,7 @@ namespace OpenNest
{
context.Token.ThrowIfCancellationRequested();
var result = filler.Fill(context.Item.Drawing, angle,
context.PlateNumber, context.Token, context.Progress, bestFits);
context.PlateNumber, context.Token, context.Progress);
if (result != null && result.Count > 0)
{
var score = FillScore.Compute(result, context.WorkArea);

View File

@@ -1,9 +1,10 @@
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using System;
using System.Collections.Generic;
using System.Threading;
using OpenNest.Geometry;
namespace OpenNest
namespace OpenNest.Engine.Strategies
{
public class FillContext
{

View File

@@ -1,10 +1,11 @@
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using OpenNest.Math;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest
namespace OpenNest.Engine.Strategies
{
public static class FillHelpers
{

View File

@@ -5,7 +5,7 @@ using System.IO;
using System.Linq;
using System.Reflection;
namespace OpenNest
namespace OpenNest.Engine.Strategies
{
public static class FillStrategyRegistry
{

View File

@@ -1,6 +1,6 @@
using System.Collections.Generic;
namespace OpenNest
namespace OpenNest.Engine.Strategies
{
public interface IFillStrategy
{

View File

@@ -1,7 +1,8 @@
using System.Collections.Generic;
using OpenNest.Engine.Fill;
using OpenNest.Math;
using System.Collections.Generic;
namespace OpenNest
namespace OpenNest.Engine.Strategies
{
public class LinearFillStrategy : IFillStrategy
{

View File

@@ -1,7 +1,8 @@
using System.Collections.Generic;
using OpenNest.Engine.BestFit;
using OpenNest.Engine.Fill;
using System.Collections.Generic;
namespace OpenNest
namespace OpenNest.Engine.Strategies
{
public class PairsFillStrategy : IFillStrategy
{

View File

@@ -1,7 +1,7 @@
using System.Collections.Generic;
using OpenNest.RectanglePacking;
using System.Collections.Generic;
namespace OpenNest
namespace OpenNest.Engine.Strategies
{
public class RectBestFitStrategy : IFillStrategy
{

View File

@@ -1,8 +1,9 @@
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using OpenNest.Geometry;
namespace OpenNest
{

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using System.Collections.Generic;
namespace OpenNest
{