Files
OpenNest/OpenNest.Engine/Jobs/Placement/PrivatePlateFill.cs
T
ajandClaude Fable 5.2 3fccf6670f perf(irregular): remember outline overlap verdicts across a solve's fills
Auto Nest's banded variant fills the same box with the same part once per
remaining quantity, and each fill's tilted-remnant step triangulated and
tested the same spacing outlines at the same places: 98 s of a 271 s
profile of N26-2J9.

OutlineOverlapMemo keeps the verdict of SpacingOutline.Overlaps by the
exact coordinates of both perimeters, so a remembered answer is the one
the test would give and no layout can change. The block catalog owns one
memo per solve and passes it to its private fills; interactive fills pass
none and test every pair as before. It holds coordinates and verdicts
only, in two bounded generations.

N26-2J9 Auto Nest: 244 s to 179 s, the same plans and result.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 14:53:05 -05:00

58 lines
2.7 KiB
C#

#nullable enable
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using OpenNest.Engine.BestFit;
using OpenNest.Engine.Fill;
using OpenNest.Engine.Jobs.Adapters;
using OpenNest.Engine.Jobs.Placement.Fillers;
using OpenNest.Geometry;
namespace OpenNest.Engine.Jobs.Placement;
/// <summary>
/// Runs the Fill strategy for one private drawing on a private plate, for callers that turn the
/// result into job poses. The caller owns the drawing and must call
/// <see cref="BestFitCache.Invalidate"/> for it when finished.
/// </summary>
internal static class PrivatePlateFill
{
/// <param name="length">X extent of the plate and work area.</param>
/// <param name="width">Y extent of the plate and work area.</param>
/// <param name="quantity">Copies wanted; zero fills the whole area.</param>
/// <param name="wholePairGrids">See <see cref="PlateFiller.WholePairGrids"/>.</param>
/// <param name="overlapMemo">See <see cref="PlateFiller.OverlapMemo"/>: a caller filling one
/// part again and again passes the same memo to each fill.</param>
internal static List<Part> Run(Drawing drawing, RotationPolicy rotation, double spacing,
double length, double width, int quantity, CancellationToken token, bool wholePairGrids = true,
OutlineOverlapMemo overlapMemo = null)
{
var plate = new Plate(new Size(width, length)) { PartSpacing = spacing };
// The drawing is private: stabilize this cache entry before Fill's candidate pruning.
// Cancelling stops the wait; the search finishes in the background and fills the cache.
var fits = BestFitCache.GetOrCompute(drawing, plate.Size.Length, plate.Size.Width, spacing,
token);
var sorted = fits.OrderBy(f => f.RotatedArea).ThenBy(f => f.Candidate.StrategyIndex)
.ThenBy(f => f.Candidate.Part2Rotation).ThenBy(f => f.Candidate.Part2Offset.X)
.ThenBy(f => f.Candidate.Part2Offset.Y).ThenBy(f => f.OptimalRotation).ToArray();
fits.Clear();
fits.AddRange(sorted);
// A positive quantity lets supporting strategies avoid surplus rows. Zero still
// fills the whole area (the cutout lattice caller requires an uncapped lattice).
var filler = new PlateFiller(plate)
{
StopAtQuantity = true,
WholePairGrids = wholePairGrids,
OverlapMemo = overlapMemo,
};
return filler.Fill(new NestItem
{
Drawing = drawing,
Quantity = quantity,
RotationStart = rotation.Start,
RotationEnd = rotation.End,
StepAngle = DrawingJobMapper.LegacyStep(rotation),
}, new Box(0, 0, length, width), null!, token);
}
}