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>
68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using OpenNest.Engine.Fill;
|
|
using OpenNest.Geometry;
|
|
using OpenNest.Math;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace OpenNest.Engine.Strategies
|
|
{
|
|
public static class FillHelpers
|
|
{
|
|
public static Pattern BuildRotatedPattern(List<Part> groupParts, double angle)
|
|
{
|
|
var pattern = new Pattern();
|
|
var center = ((IEnumerable<IBoundable>)groupParts).GetBoundingBox().Center;
|
|
|
|
foreach (var part in groupParts)
|
|
{
|
|
var clone = (Part)part.Clone();
|
|
clone.UpdateBounds();
|
|
|
|
if (!angle.IsEqualTo(0))
|
|
clone.Rotate(angle, center);
|
|
|
|
pattern.Parts.Add(clone);
|
|
}
|
|
|
|
pattern.UpdateBounds();
|
|
return pattern;
|
|
}
|
|
|
|
public static List<Part> FillPattern(FillLinear engine, List<Part> groupParts, List<double> angles, Box workArea)
|
|
{
|
|
var results = new ConcurrentBag<(List<Part> Parts, FillScore Score)>();
|
|
|
|
Parallel.ForEach(angles, angle =>
|
|
{
|
|
var pattern = BuildRotatedPattern(groupParts, angle);
|
|
|
|
if (pattern.Parts.Count == 0)
|
|
return;
|
|
|
|
var h = engine.Fill(pattern, NestDirection.Horizontal);
|
|
if (h != null && h.Count > 0)
|
|
results.Add((h, FillScore.Compute(h, workArea)));
|
|
|
|
var v = engine.Fill(pattern, NestDirection.Vertical);
|
|
if (v != null && v.Count > 0)
|
|
results.Add((v, FillScore.Compute(v, workArea)));
|
|
});
|
|
|
|
List<Part> best = null;
|
|
var bestScore = default(FillScore);
|
|
|
|
foreach (var res in results)
|
|
{
|
|
if (best == null || res.Score > bestScore)
|
|
{
|
|
best = res.Parts;
|
|
bestScore = res.Score;
|
|
}
|
|
}
|
|
|
|
return best;
|
|
}
|
|
}
|
|
}
|