mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 14:31:36 -05:00
Expand Spacing kept the first selected part fixed and stalled on full plates. - A pair of selected parts now shares each push (later part half, earlier part the rest, later part any remainder), so no selected part is an anchor. Both shares run to the full target, so a part between two short gaps no longer ping-pongs while its partners never move. - Clamps act like the work-area edge: a part may close on the keep-out but never enter it, and the clamp gap neither chases the target spacing nor counts as the achieved spacing. Before, clamps held their full entry gap and a part resting just above one capped the whole search. - A part flush on an edge can slide along it again. A push that leaned into the edge by rounding (parts turned a quarter or half) divided zero room by a tiny component and pinned every move. - Faster search with identical layouts: per-part pair lists, clearances remembered at the positions measured, box-proven clamp pairs skipped, trial-move gaps measured only up to their threshold, the overlap clipping run only for outlines that touch, cross or nest, and ring distances measured at offsets without copying outlines. Clearance gains the bounded and offset distance used for this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
3.4 KiB
C#
83 lines
3.4 KiB
C#
using OpenNest.CNC;
|
|
using OpenNest.Engine.Fill;
|
|
using OpenNest.Engine.Tests.Jobs;
|
|
using OpenNest.Geometry;
|
|
using Xunit;
|
|
|
|
namespace OpenNest.Engine.Tests.Fill;
|
|
|
|
public class ExpanderRemoteObliquePathTests
|
|
{
|
|
public static IEnumerable<object[]> Cases()
|
|
{
|
|
foreach (var quadrant in new[] { 1, 2, 3, 4 })
|
|
foreach (var transpose in new[] { false, true })
|
|
foreach (var cutoff in new[] { false, true })
|
|
foreach (var expand in new[] { false, true })
|
|
yield return new object[] { quadrant, transpose, cutoff, expand };
|
|
}
|
|
|
|
[Theory]
|
|
[MemberData(nameof(Cases))]
|
|
public void RemoteObliqueOpenPathMustNotPinSafeParallelGrowth(
|
|
int quadrant, bool transpose, bool cutoff, bool expand)
|
|
{
|
|
var origin = new Vector(quadrant is 2 or 3 ? -100 : 0,
|
|
quadrant is 3 or 4 ? -100 : 0);
|
|
Vector Swap(double x, double y) => transpose ? new Vector(y, x) : new Vector(x, y);
|
|
var plate = new Plate(new Size(100, 100))
|
|
{
|
|
Quadrant = quadrant,
|
|
EdgeSpacing = new Spacing(0, 0),
|
|
};
|
|
var anchorPose = origin + Swap(40, 40);
|
|
var moverPose = origin + Swap(43, 40);
|
|
var anchor = new Part(
|
|
new Drawing("anchor", TestDrawingFactory.Rectangle(2, 2)), anchorPose);
|
|
var mover = new Part(new Drawing("mover", TestDrawingFactory.Rectangle(2, 2)), moverPose);
|
|
plate.Parts.Add(anchor);
|
|
plate.Parts.Add(mover);
|
|
if (cutoff)
|
|
{
|
|
var path = new Program();
|
|
var start = Swap(18, 32);
|
|
var middle = Swap(68, 64);
|
|
var high = Swap(68, 80);
|
|
var tail = Swap(75, 80);
|
|
path.MoveTo(start.X, start.Y);
|
|
path.LineTo(middle.X, middle.Y);
|
|
path.LineTo(high.X, high.Y);
|
|
path.LineTo(tail.X, tail.Y);
|
|
plate.Parts.Add(new Part(new Drawing("neutral-path", path) { IsCutOff = true }, origin));
|
|
}
|
|
// First line is y=.64*x+20.48. The anchor's nearest corner (40,42)
|
|
// has exact gap 4.08/sqrt(1+.64^2)>3; mover (43,42) >5.
|
|
Vector end;
|
|
Vector anchorEnd;
|
|
if (expand)
|
|
{
|
|
var result = Expander.Expand(new List<Part> { anchor, mover }, plate,
|
|
new Expander.Options { MaxSpacing = 2 });
|
|
end = mover.Location;
|
|
anchorEnd = anchor.Location;
|
|
Assert.True(result.AchievedSpacing >= 1.99,
|
|
$"Remote cutoff pinned mover: spacing={result.AchievedSpacing:R}, violations={result.Violations.Count}");
|
|
}
|
|
else
|
|
{
|
|
var result = Expander.Separate(new List<Part> { anchor, mover }, plate, 2);
|
|
end = result.Positions[1];
|
|
anchorEnd = result.Positions[0];
|
|
Assert.True(result.Converged,
|
|
$"Remote cutoff pinned mover: end=({end.X:R},{end.Y:R}), violations={result.Violations.Count}");
|
|
Assert.Equal(moverPose.X, mover.Location.X);
|
|
Assert.Equal(moverPose.Y, mover.Location.Y);
|
|
}
|
|
// Both selected parts share the opening along the pair's axis.
|
|
var opened = (end - anchorEnd) - (moverPose - anchorPose);
|
|
Assert.True(transpose ? opened.Y >= 0.999 : opened.X >= 0.999,
|
|
$"opened=({opened.X:R},{opened.Y:R})");
|
|
Assert.Equal(0, transpose ? opened.X : opened.Y, 9);
|
|
}
|
|
}
|