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
{

View File

@@ -1,10 +1,9 @@
using System.Collections.Generic;
using ModelContextProtocol.Server;
using OpenNest.Engine.Fill;
using OpenNest.Math;
using System.ComponentModel;
using System.Linq;
using System.Text;
using ModelContextProtocol.Server;
using OpenNest.Geometry;
using OpenNest.Math;
namespace OpenNest.Mcp.Tools
{

View File

@@ -1,10 +1,11 @@
using ModelContextProtocol.Server;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using ModelContextProtocol.Server;
using OpenNest.Geometry;
namespace OpenNest.Mcp.Tools
{

View File

@@ -1,3 +1,5 @@
using OpenNest.Engine.Fill;
namespace OpenNest.Tests;
public class AccumulatingProgressTests

View File

@@ -1,3 +1,4 @@
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
namespace OpenNest.Tests;

View File

@@ -1,4 +1,5 @@
using OpenNest.CNC;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
namespace OpenNest.Tests;

View File

@@ -1,3 +1,5 @@
using OpenNest.Engine.Fill;
namespace OpenNest.Tests;
public class FillScoreTests

View File

@@ -1,3 +1,4 @@
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
namespace OpenNest.Tests;

View File

@@ -1,5 +1,4 @@
using OpenNest;
using OpenNest.Engine;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
namespace OpenNest.Tests;

View File

@@ -1,3 +1,4 @@
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
namespace OpenNest.Tests;

View File

@@ -1,3 +1,4 @@
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using OpenNest.IO;

View File

@@ -1,3 +1,4 @@
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
namespace OpenNest.Tests;

View File

@@ -1,3 +1,5 @@
using OpenNest.Engine.Strategies;
namespace OpenNest.Tests.Strategies;
public class FillStrategyRegistryTests

View File

@@ -1,9 +1,10 @@
using System.Collections.Generic;
using OpenNest.Controls;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using OpenNest.Controls;
using OpenNest.Geometry;
namespace OpenNest.Actions
{
@@ -71,7 +72,7 @@ namespace OpenNest.Actions
{
if (plateView.ViewScale != lastScale)
{
parts.ForEach(p =>
parts.ForEach(p =>
{
p.Update(plateView);
p.Draw(e.Graphics);
@@ -146,11 +147,11 @@ namespace OpenNest.Actions
PushDirection hDir, vDir;
switch (plateView.Plate.Quadrant)
{
case 1: hDir = PushDirection.Left; vDir = PushDirection.Down; break;
case 2: hDir = PushDirection.Right; vDir = PushDirection.Down; break;
case 3: hDir = PushDirection.Right; vDir = PushDirection.Up; break;
case 4: hDir = PushDirection.Left; vDir = PushDirection.Up; break;
default: hDir = PushDirection.Left; vDir = PushDirection.Down; break;
case 1: hDir = PushDirection.Left; vDir = PushDirection.Down; break;
case 2: hDir = PushDirection.Right; vDir = PushDirection.Down; break;
case 3: hDir = PushDirection.Right; vDir = PushDirection.Up; break;
case 4: hDir = PushDirection.Left; vDir = PushDirection.Up; break;
default: hDir = PushDirection.Left; vDir = PushDirection.Down; break;
}
// Phase 1: BB-only push to get past irregular geometry quickly.

View File

@@ -1,4 +1,11 @@
using System;
using OpenNest.Actions;
using OpenNest.CNC;
using OpenNest.Collections;
using OpenNest.Engine.Fill;
using OpenNest.Forms;
using OpenNest.Geometry;
using OpenNest.Math;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
@@ -9,12 +16,6 @@ using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenNest.Actions;
using OpenNest.CNC;
using OpenNest.Collections;
using OpenNest.Forms;
using OpenNest.Geometry;
using OpenNest.Math;
using Action = OpenNest.Actions.Action;
using Timer = System.Timers.Timer;
@@ -59,7 +60,7 @@ namespace OpenNest.Controls
public List<LayoutPart> SelectedParts;
public ReadOnlyCollection<LayoutPart> Parts;
public event EventHandler<ItemAddedEventArgs<Part>> PartAdded;
public event EventHandler<ItemRemovedEventArgs<Part>> PartRemoved;
public event EventHandler StatusChanged;
@@ -381,7 +382,7 @@ namespace OpenNest.Controls
e.Graphics.DrawLine(ColorScheme.OriginPen, origin.X, 0, origin.X, Height);
e.Graphics.DrawLine(ColorScheme.OriginPen, 0, origin.Y, Width, origin.Y);
}
e.Graphics.TranslateTransform(origin.X, origin.Y);
DrawPlate(e.Graphics);
@@ -1001,7 +1002,7 @@ namespace OpenNest.Controls
{
base.ZoomToPoint(pt, zoomFactor, false);
if (redraw)
if (redraw)
Invalidate();
}

View File

@@ -1,4 +1,12 @@
using System;
using OpenNest.Actions;
using OpenNest.Collections;
using OpenNest.Engine.BestFit;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using OpenNest.Gpu;
using OpenNest.IO;
using OpenNest.Properties;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
@@ -7,13 +15,6 @@ using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenNest.Actions;
using OpenNest.Collections;
using OpenNest.Engine.BestFit;
using OpenNest.Gpu;
using OpenNest.Geometry;
using OpenNest.IO;
using OpenNest.Properties;
namespace OpenNest.Forms
{
@@ -812,7 +813,7 @@ namespace OpenNest.Forms
if (form.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
var items = form.GetNestItems();
if (!items.Any(it => it.Quantity > 0))
@@ -896,7 +897,7 @@ namespace OpenNest.Forms
private void SequenceAllPlates_Click(object sender, EventArgs e)
{
if (activeForm == null)
if (activeForm == null)
return;
activeForm.AutoSequenceAllPlates();

View File

@@ -1,9 +1,10 @@
using OpenNest.Controls;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using OpenNest.Controls;
using OpenNest.Geometry;
using GeoSize = OpenNest.Geometry.Size;
namespace OpenNest.Forms

View File

@@ -1,9 +1,10 @@
using OpenNest.Controls;
using OpenNest.Engine.Fill;
using OpenNest.Geometry;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using OpenNest.Controls;
using OpenNest.Geometry;
namespace OpenNest.Forms
{