mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-05 16:29:27 -05:00
feat(engine): grow edge strips with Expand Spacing
Expand Spacing widened gaps between parts but left each part's strip to the sheet edge at the plate's edge spacing, so past twice that spacing the edge strip became the thinnest web on the plate. A strip takes heat from one cut while a web between parts takes it from two, so each edge strip now holds at least half the spacing (never less than EdgeSpacing). The pair search pushes edge parts inward and only accepts a spacing whose strips hold. The pattern stretch sizes each axis's strips from the smallest gap that axis widens, so stretching along the rows before the rows open does not use up the edge room. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6834f2905a
commit
55e8ea6084
6 files changed
+322
-63
No files matched your search
@@ -68,6 +68,27 @@ public class ExpanderPatternTests
|
||||
|
||||
private static double DiskGap(Part a, Part b) => a.Location.DistanceTo(b.Location) - 2 * Radius;
|
||||
|
||||
/// <summary>The smallest gap between disks in different rows: the gap a
|
||||
/// stretch across the rows opens.</summary>
|
||||
private static double RowToRowGap(List<Part> parts) => parts
|
||||
.SelectMany((a, i) => parts.Skip(i + 1)
|
||||
.Where(b => System.Math.Abs(a.Location.Y - b.Location.Y) > 1e-6)
|
||||
.Select(b => DiskGap(a, b)))
|
||||
.Min();
|
||||
|
||||
/// <summary>Asserts the bottom and top sheet-edge strips hold half the gap a
|
||||
/// stretch across the rows opened, and the top one no more than that.</summary>
|
||||
private static void AssertRowEdgeStrips(Plate plate, List<Part> parts)
|
||||
{
|
||||
var half = RowToRowGap(parts) / 2;
|
||||
var sheet = plate.BoundingBox(false);
|
||||
var bottom = parts.Min(p => p.BoundingBox.Bottom) - sheet.Bottom;
|
||||
var top = sheet.Top - parts.Max(p => p.BoundingBox.Top);
|
||||
Assert.True(bottom >= half - 1e-6, $"bottom strip {bottom} under half the row gap {half}");
|
||||
Assert.True(top >= half - 1e-6, $"top strip {top} under half the row gap {half}");
|
||||
Assert.True(top <= half + 0.02, $"top strip {top} wider than half the row gap {half}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Expand_StaggeredFillTightAlongX_StretchesOnlyTheRowPitch()
|
||||
{
|
||||
@@ -93,11 +114,9 @@ public class ExpanderPatternTests
|
||||
Assert.Equal(rowPitch, odd[1] - odd[0], 6);
|
||||
Assert.Equal(even[0] + rowPitch / 2, odd[0], 6);
|
||||
|
||||
// The pattern fills the height and only the diagonal gap opened up.
|
||||
var work = plate.WorkArea();
|
||||
Assert.True(parts.Min(p => p.BoundingBox.Bottom) >= work.Bottom - 1e-9);
|
||||
Assert.True(parts.Max(p => p.BoundingBox.Top) <= work.Top + 1e-9);
|
||||
Assert.True(work.Top - parts.Max(p => p.BoundingBox.Top) < 0.02);
|
||||
// The pattern fills the height but for edge strips of half the diagonal
|
||||
// gap, and only the diagonal gap opened up.
|
||||
AssertRowEdgeStrips(plate, parts);
|
||||
Assert.Equal(rowMateGap, DiskGap(parts[0], parts[5]), 6);
|
||||
Assert.True(DiskGap(parts[0], parts[3]) > 1, $"diagonal gap {DiskGap(parts[0], parts[3])}");
|
||||
Assert.Equal(rowMateGap, result.AchievedSpacing, 2);
|
||||
@@ -140,13 +159,12 @@ public class ExpanderPatternTests
|
||||
Assert.Equal(5, spreadYs.Count);
|
||||
for (var row = 1; row < 5; row++)
|
||||
Assert.True(spreadYs[row] - spreadYs[row - 1] > rowYs[row] - rowYs[row - 1] + 0.1);
|
||||
var work = plate.WorkArea();
|
||||
Assert.True(work.Top - parts.Max(p => p.BoundingBox.Top) < 0.02);
|
||||
AssertRowEdgeStrips(plate, parts);
|
||||
Assert.True(parts.SelectMany((a, i) => parts.Skip(i + 1).Select(b => DiskGap(a, b))).Min() >= entryGap - 1e-6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Expand_GridWithRoomBothWays_FillsTheWorkAreaEvenly()
|
||||
public void Expand_GridWithRoomBothWays_FillsThePlateEvenlyWithHalfGapEdgeStrips()
|
||||
{
|
||||
var plate = MakePlate(40, 30, 0.5);
|
||||
var drawing = new Drawing("square", TestDrawingFactory.Rectangle(4, 4));
|
||||
@@ -167,11 +185,18 @@ public class ExpanderPatternTests
|
||||
Assert.Equal(ys[1] - ys[0], ys[2] - ys[1], 6);
|
||||
Assert.True(xs[1] - xs[0] > 5.5 && ys[1] - ys[0] > 5.5);
|
||||
|
||||
var work = plate.WorkArea();
|
||||
Assert.True(parts.Min(p => p.BoundingBox.Left) >= work.Left - 1e-9);
|
||||
Assert.True(parts.Max(p => p.BoundingBox.Right) <= work.Right + 1e-9);
|
||||
Assert.True(work.Right - parts.Max(p => p.BoundingBox.Right) + parts.Min(p => p.BoundingBox.Left) - work.Left < 0.02);
|
||||
Assert.True(work.Top - parts.Max(p => p.BoundingBox.Top) + parts.Min(p => p.BoundingBox.Bottom) - work.Bottom < 0.02);
|
||||
// Each edge strip is half the gap along its axis: 40 = 3 * 4 + 3 * gap
|
||||
// across X and 30 = 3 * 4 + 3 * gap across Y.
|
||||
var gapX = xs[1] - xs[0] - 4;
|
||||
var gapY = ys[1] - ys[0] - 4;
|
||||
Assert.Equal(28.0 / 3, gapX, 1);
|
||||
Assert.Equal(6, gapY, 1);
|
||||
Assert.Equal(gapX / 2, parts.Min(p => p.BoundingBox.Left), 1);
|
||||
Assert.Equal(gapX / 2, 40 - parts.Max(p => p.BoundingBox.Right), 1);
|
||||
Assert.Equal(gapY / 2, parts.Min(p => p.BoundingBox.Bottom), 1);
|
||||
Assert.Equal(gapY / 2, 30 - parts.Max(p => p.BoundingBox.Top), 1);
|
||||
Assert.True(parts.Min(p => p.BoundingBox.Left) >= gapX / 2 - 1e-6);
|
||||
Assert.True(parts.Min(p => p.BoundingBox.Bottom) >= gapY / 2 - 1e-6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in new issue
Block a user