refactor(engine): extract AccumulatingProgress from StripNestEngine
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
35
OpenNest.Engine/AccumulatingProgress.cs
Normal file
35
OpenNest.Engine/AccumulatingProgress.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenNest
|
||||
{
|
||||
/// <summary>
|
||||
/// Wraps an IProgress to prepend previously placed parts to each report,
|
||||
/// so the UI shows the full picture during incremental fills.
|
||||
/// </summary>
|
||||
internal class AccumulatingProgress : IProgress<NestProgress>
|
||||
{
|
||||
private readonly IProgress<NestProgress> inner;
|
||||
private readonly List<Part> previousParts;
|
||||
|
||||
public AccumulatingProgress(IProgress<NestProgress> inner, List<Part> previousParts)
|
||||
{
|
||||
this.inner = inner;
|
||||
this.previousParts = previousParts;
|
||||
}
|
||||
|
||||
public void Report(NestProgress value)
|
||||
{
|
||||
if (value.BestParts != null && previousParts.Count > 0)
|
||||
{
|
||||
var combined = new List<Part>(previousParts.Count + value.BestParts.Count);
|
||||
combined.AddRange(previousParts);
|
||||
combined.AddRange(value.BestParts);
|
||||
value.BestParts = combined;
|
||||
value.BestPartCount = combined.Count;
|
||||
}
|
||||
|
||||
inner.Report(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user