refactor(fill): share StartBeyond between end-row refill and grid-end insertion

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-11-23 05:48:42 -05:00
1 parent 5fb52b1aaf
commit 231d1264ab
3 files changed
+53 -74

No files matched your search

+1 -37
View File
@@ -185,7 +185,7 @@ namespace OpenNest.Engine.Fill
for (var i = 0; i <= samples; i++)
{
var across = lo + (hi - lo) * i / samples;
var copy = StartBeyond(template, workArea, spacing, slide, across, vertical);
var copy = SlideStart.Beyond(template, workArea, spacing, slide, across, vertical);
moving.Clear();
moving.Add(copy);
var travel = Compactor.Push(moving, workArea, direction, obstacleSet);
@@ -208,42 +208,6 @@ namespace OpenNest.Engine.Fill
return best;
}
/// <summary>
/// A copy of <paramref name="template"/> just beyond the work-area edge the slide
/// starts from, its inner bound at <paramref name="across"/> across the row.
/// </summary>
private static Part StartBeyond(
Part template,
Box workArea,
double spacing,
PushDirection slide,
double across,
bool vertical
)
{
var box = template.BoundingBox;
var gap = spacing + 1.0;
double dx, dy;
if (vertical)
{
dy = across - box.Bottom;
dx = slide == PushDirection.Left
? workArea.Right + gap - box.Left
: workArea.Left - gap - box.Right;
}
else
{
dx = across - box.Left;
dy = slide == PushDirection.Down
? workArea.Top + gap - box.Bottom
: workArea.Bottom - gap - box.Top;
}
var copy = template.CloneAtOffset(new Vector(dx, dy));
copy.UpdateBounds();
return copy;
}
/// <summary>How far the copy got: smaller is deeper along the slide.</summary>
private static double LeadingEdge(Box box, PushDirection slide) =>
slide switch
+1 -37
View File
@@ -206,7 +206,7 @@ namespace OpenNest.Engine.Fill
void Try(Part template, double across)
{
var copy = StartBeyond(template, area, spacing, slide, across, horizontal);
var copy = SlideStart.Beyond(template, area, spacing, slide, across, horizontal);
moving.Clear();
moving.Add(copy);
if (Compactor.Push(moving, area, direction, obstacles) <= 0)
@@ -264,42 +264,6 @@ namespace OpenNest.Engine.Fill
return best;
}
/// <summary>
/// A copy of <paramref name="template"/> just beyond the area edge the slide starts from,
/// its lower bound across the slide at <paramref name="across"/>.
/// </summary>
private static Part StartBeyond(
Part template,
Box area,
double spacing,
PushDirection slide,
double across,
bool horizontal
)
{
var box = template.BoundingBox;
var gap = spacing + 1.0;
double dx, dy;
if (horizontal)
{
dy = across - box.Bottom;
dx = slide == PushDirection.Left
? area.Right + gap - box.Left
: area.Left - gap - box.Right;
}
else
{
dx = across - box.Left;
dy = slide == PushDirection.Down
? area.Top + gap - box.Bottom
: area.Bottom - gap - box.Top;
}
var copy = template.CloneAtOffset(new Vector(dx, dy));
copy.UpdateBounds();
return copy;
}
/// <summary>How far the copy got: smaller is deeper along the slide.</summary>
private static double LeadingEdge(Box box, PushDirection slide) =>
slide switch
+51
View File
@@ -0,0 +1,51 @@
using OpenNest.Geometry;
namespace OpenNest.Engine.Fill
{
/// <summary>Starting positions for copies slid into an area with a <see cref="Compactor"/> push.</summary>
internal static class SlideStart
{
/// <summary>
/// A copy of <paramref name="template"/> just beyond the area edge the slide starts from
/// (one part spacing plus one unit clear of it), its lower bound across the slide at
/// <paramref name="across"/>.
/// </summary>
/// <param name="slideAlongX">
/// True when <paramref name="slide"/> is <see cref="PushDirection.Left"/> or
/// <see cref="PushDirection.Right"/>: the copy's bottom goes to <paramref name="across"/>
/// and it starts beyond the area's right or left edge. False for an up/down slide: its left
/// goes to <paramref name="across"/> and it starts beyond the area's top or bottom edge.
/// </param>
internal static Part Beyond(
Part template,
Box area,
double spacing,
PushDirection slide,
double across,
bool slideAlongX
)
{
var box = template.BoundingBox;
var gap = spacing + 1.0;
double dx, dy;
if (slideAlongX)
{
dy = across - box.Bottom;
dx = slide == PushDirection.Left
? area.Right + gap - box.Left
: area.Left - gap - box.Right;
}
else
{
dx = across - box.Left;
dy = slide == PushDirection.Down
? area.Top + gap - box.Bottom
: area.Bottom - gap - box.Top;
}
var copy = template.CloneAtOffset(new Vector(dx, dy));
copy.UpdateBounds();
return copy;
}
}
}