refactor: extract IPairEvaluator interface from PairEvaluator
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using OpenNest.Converters;
|
using OpenNest.Converters;
|
||||||
using OpenNest.Engine.BestFit.Tiling;
|
using OpenNest.Engine.BestFit.Tiling;
|
||||||
using OpenNest.Geometry;
|
using OpenNest.Geometry;
|
||||||
@@ -9,12 +11,12 @@ namespace OpenNest.Engine.BestFit
|
|||||||
{
|
{
|
||||||
public class BestFitFinder
|
public class BestFitFinder
|
||||||
{
|
{
|
||||||
private readonly PairEvaluator _evaluator;
|
private readonly IPairEvaluator _evaluator;
|
||||||
private readonly BestFitFilter _filter;
|
private readonly BestFitFilter _filter;
|
||||||
|
|
||||||
public BestFitFinder(double maxPlateWidth, double maxPlateHeight)
|
public BestFitFinder(double maxPlateWidth, double maxPlateHeight, IPairEvaluator evaluator = null)
|
||||||
{
|
{
|
||||||
_evaluator = new PairEvaluator();
|
_evaluator = evaluator ?? new PairEvaluator();
|
||||||
_filter = new BestFitFilter
|
_filter = new BestFitFilter
|
||||||
{
|
{
|
||||||
MaxPlateWidth = maxPlateWidth,
|
MaxPlateWidth = maxPlateWidth,
|
||||||
@@ -30,12 +32,16 @@ namespace OpenNest.Engine.BestFit
|
|||||||
{
|
{
|
||||||
var strategies = BuildStrategies(drawing);
|
var strategies = BuildStrategies(drawing);
|
||||||
|
|
||||||
var allCandidates = new List<PairCandidate>();
|
var candidateBags = new ConcurrentBag<List<PairCandidate>>();
|
||||||
|
|
||||||
foreach (var strategy in strategies)
|
Parallel.ForEach(strategies, strategy =>
|
||||||
allCandidates.AddRange(strategy.GenerateCandidates(drawing, spacing, stepSize));
|
{
|
||||||
|
candidateBags.Add(strategy.GenerateCandidates(drawing, spacing, stepSize));
|
||||||
|
});
|
||||||
|
|
||||||
var results = allCandidates.Select(c => _evaluator.Evaluate(c)).ToList();
|
var allCandidates = candidateBags.SelectMany(c => c).ToList();
|
||||||
|
|
||||||
|
var results = _evaluator.EvaluateAll(allCandidates);
|
||||||
|
|
||||||
_filter.Apply(results);
|
_filter.Apply(results);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace OpenNest.Engine.BestFit
|
||||||
|
{
|
||||||
|
public interface IPairEvaluator
|
||||||
|
{
|
||||||
|
List<BestFitResult> EvaluateAll(List<PairCandidate> candidates);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,29 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using OpenNest.Converters;
|
using OpenNest.Converters;
|
||||||
using OpenNest.Geometry;
|
using OpenNest.Geometry;
|
||||||
using OpenNest.Math;
|
using OpenNest.Math;
|
||||||
|
|
||||||
namespace OpenNest.Engine.BestFit
|
namespace OpenNest.Engine.BestFit
|
||||||
{
|
{
|
||||||
public class PairEvaluator
|
public class PairEvaluator : IPairEvaluator
|
||||||
{
|
{
|
||||||
private const double ChordTolerance = 0.01;
|
private const double ChordTolerance = 0.01;
|
||||||
|
|
||||||
|
public List<BestFitResult> EvaluateAll(List<PairCandidate> candidates)
|
||||||
|
{
|
||||||
|
var resultBag = new ConcurrentBag<BestFitResult>();
|
||||||
|
|
||||||
|
Parallel.ForEach(candidates, c =>
|
||||||
|
{
|
||||||
|
resultBag.Add(Evaluate(c));
|
||||||
|
});
|
||||||
|
|
||||||
|
return resultBag.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
public BestFitResult Evaluate(PairCandidate candidate)
|
public BestFitResult Evaluate(PairCandidate candidate)
|
||||||
{
|
{
|
||||||
var drawing = candidate.Drawing;
|
var drawing = candidate.Drawing;
|
||||||
|
|||||||
Reference in New Issue
Block a user