diff --git a/AGENTS.md b/AGENTS.md
index ad4f4021..135336c3 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -50,7 +50,7 @@ Releases: follow [the release procedure](docs/releasing.md) and `scripts/Publish
## Geometry and ownership safeguards
- Marks are not material: use `SpecialLayers.IsMaterial` when deriving nesting/collision geometry; exclude rapid and scribe moves without removing them from display, cutting time or posts.
-- Engine/validator collision paths retain the hand-written `Collision` kernel; its GPU port is on hold. Material-overlap diagnostics use Clipper2 per pair for connected shared-material islands and interior markers; see [material-overlap diagnostics](docs/geometry/visual-overlap-check.md). Polygon consumers use `ClipperBridge`; directional-distance consumers retain native-arc offsets. Validation uses `OffsetForValidation` and `NestTolerances.SpacingSlack`, not conservative display/preparation padding; Auto Nest's layout check, the runner's candidate validation and the pre-post part-spacing review all find spacing candidates with Core's `SpacingOutline` and confirm them on `NativeContours` (the outline circumscribes arcs by more than the slack), so they agree; `NestLayoutCheck.Clears` skips the confirmation and stays stricter for engine certification. Do not loosen tolerances to hide failures.
+- Engine/validator collision paths retain the hand-written `Collision` kernel; its GPU port is on hold. Material-overlap diagnostics use Clipper2 per pair for connected shared-material islands and interior markers; see [material-overlap diagnostics](docs/geometry/visual-overlap-check.md). Polygon consumers use `ClipperBridge`; directional-distance consumers retain native-arc offsets. Validation uses `OffsetForValidation` and `NestTolerances.SpacingSlack`, not conservative display/preparation padding; Auto Nest's layout check, the runner's candidate validation and the pre-post part-spacing review all find spacing candidates with Core's `SpacingOutline` and confirm them on `NativeContours` (the outline circumscribes arcs by more than the slack), so they agree; an outlined sheet's edge test confirms the same way (`SheetOutline.Holds` with `NativeContours.Region`); `NestLayoutCheck.Clears` skips the confirmation and stays stricter for engine certification. Do not loosen tolerances to hide failures.
- `FillLinear` geometry caches are per public call, keyed by `Program` reference identity; never share them across calls/threads. `PartOverlapChecker` is per check; parts/programs must not mutate during its lifetime.
- `FillScore` ranks count, utilization, compactness; exact ties keep the current layout. Custom comparers remain authoritative. Preserve extents' negative/nonfinite-input fallback, pair preparation and adjusted-column overlap checks. Do not remove bounds recomputations without threshold/rounding characterization.
- `ObservableList` events own drawing/plate quantity tracking; avoid double accounting. Cutoff parts are excluded from quantity, utilization and overlap checks.
diff --git a/OpenNest.Core/Diagnostics/PlateEdgeReview.cs b/OpenNest.Core/Diagnostics/PlateEdgeReview.cs
index b9e1c7b4..b7c0f2e1 100644
--- a/OpenNest.Core/Diagnostics/PlateEdgeReview.cs
+++ b/OpenNest.Core/Diagnostics/PlateEdgeReview.cs
@@ -25,6 +25,13 @@ namespace OpenNest.Diagnostics;
/// it accepted stays clear. Shortfalls up to pass. Leads
/// may run into the edge spacing; only off the sheet do they warn.
///
+///
+/// The sheet's box is tested on the material's true bounds. An outline is tested on the
+/// , whose circumscribed arcs reach past the material by more than
+/// the slack, and a failure there is confirmed on
+/// (), so a round
+/// part resting on an edge reads the same on an outlined sheet as on a rectangle.
+///
/// Cut-off parts are exempt: they run to the sheet edge by design.
///
internal static class PlateEdgeReview
@@ -139,20 +146,24 @@ internal static class PlateEdgeReview
var bounds = profile.Perimeter.BoundingBox.Translate(location);
if (Describe(Furthest(null, bounds, bounds.Center, frame.Sheet)) is { } past)
return past;
+ // An outlined sheet: the spacing outline finds the candidates and the native contours
+ // confirm them, as for part spacing, so an arc resting on an edge is not a finding.
PathsD region = null;
+ PathsD native = null;
+ PathsD Native() => native ??= NativeContours.Region(profile.Perimeter, location);
if (frame.Outline != null)
{
var material = SpacingOutline.Build(profile, location, 0)
?? throw new ArgumentException("Part material has no closed perimeter.");
region = new PathsD { ClipperBridge.ToPath(material.Perimeter, positive: true) };
- if (!frame.Outline.Holds(region, 0, frame.Origin, Slack))
+ if (!frame.Outline.Holds(region, Native, 0, frame.Origin, Slack))
return new Verdict(true, "lies outside the plate's outline or over one of its obstacles.",
bounds.Center);
}
if (Shortest(bounds, frame.Sheet, frame.Work) is { } close)
return new Verdict(false, $"is outside the work area: {close.Gap:F3} from the plate's {close.Edge} "
+ $"edge, inside its {close.Spacing:F3} edge spacing.", close.Marker);
- if (region != null && frame.Inset > 0 && !frame.Outline.Holds(region, frame.Inset, frame.Origin, Slack))
+ if (region != null && frame.Inset > 0 && !frame.Outline.Holds(region, Native, frame.Inset, frame.Origin, Slack))
return new Verdict(false, $"is outside the work area: inside the {frame.Inset:F3} edge spacing of the "
+ "plate's outline or one of its obstacles.", bounds.Center);
return null;
diff --git a/OpenNest.Core/Geometry/NativeContours.cs b/OpenNest.Core/Geometry/NativeContours.cs
index f5628dee..a5854c44 100644
--- a/OpenNest.Core/Geometry/NativeContours.cs
+++ b/OpenNest.Core/Geometry/NativeContours.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
+using Clipper2Lib;
using OpenNest.Math;
namespace OpenNest.Geometry
@@ -11,7 +12,8 @@ namespace OpenNest.Geometry
/// so two convex arcs facing each other exactly at the spacing can overlap there; these
/// contours measure that gap to within a tenth of the slack. Every spacing verdict (Auto
/// Nest's layout check, the whole-job runner's candidate validation and the pre-post review)
- /// confirms with them, so none can disagree.
+ /// confirms with them, so none can disagree. confirms an outlined
+ /// sheet's edge test the same way.
///
public sealed class NativeContours
{
@@ -48,6 +50,27 @@ namespace OpenNest.Geometry
};
}
+ ///
+ /// A perimeter (already rotated) at as a Clipper region, to
+ /// confirm a sheet-edge candidate the found on an outlined
+ /// sheet. Arcs are circumscribed at and the result is clipped to the
+ /// perimeter's own bounds, which a circumscribed arc reaches past and the material never
+ /// does. It always contains the material, so nothing past an edge is hidden, and a round
+ /// part resting on a straight edge of the sheet's box is judged as a square one is.
+ ///
+ public static PathsD Region(Shape perimeter, Vector location)
+ {
+ System.ArgumentNullException.ThrowIfNull(perimeter);
+ var path = ClipperBridge.ToPath(World(perimeter, location, ChordTolerance), positive: true);
+ var bounds = perimeter.BoundingBox.Translate(location);
+ var box = new PathD
+ {
+ new PointD(bounds.Left, bounds.Bottom), new PointD(bounds.Right, bounds.Bottom),
+ new PointD(bounds.Right, bounds.Top), new PointD(bounds.Left, bounds.Top),
+ };
+ return Clipper.Intersect(new PathsD { path }, new PathsD { box }, FillRule.NonZero, ClipperBridge.Precision);
+ }
+
///
/// True when the two parts are closer than less
/// , or share material: a boundary within that
diff --git a/OpenNest.Core/SheetOutline.cs b/OpenNest.Core/SheetOutline.cs
index 82b4b70b..a85bc35a 100644
--- a/OpenNest.Core/SheetOutline.cs
+++ b/OpenNest.Core/SheetOutline.cs
@@ -134,6 +134,23 @@ namespace OpenNest
return outside.Sum(p => System.Math.Abs(Clipper.Area(p))) <= 0;
}
+ ///
+ /// for a part's material, judged as part
+ /// spacing is. , the perimeter of the part's
+ /// , is the candidate test: it circumscribes arcs by up to its
+ /// chord tolerance, more than the slacks in use, so a round part whose material keeps the
+ /// inset can fail it. A failure is confirmed on , the part's
+ /// , built only then. Both contain the material, so a
+ /// part past the usable area by more than the slack fails both. Auto Nest's layout check,
+ /// the whole-job runner's candidate validation and the pre-post edge review all judge an
+ /// outlined sheet this way, each with its own slack.
+ ///
+ public bool Holds(PathsD outline, Func native, double inset, Vector origin, double slack)
+ {
+ ArgumentNullException.ThrowIfNull(native);
+ return Holds(outline, inset, origin, slack) || Holds(native(), inset, origin, slack);
+ }
+
/// This outline turned a quarter turn about the origin, re-normalized to start
/// at the origin, as turns the sheet.
public SheetOutline Rotated90(RotationType direction)
diff --git a/OpenNest.Engine.Tests/Fill/OutlinePushTests.cs b/OpenNest.Engine.Tests/Fill/OutlinePushTests.cs
index 5903c913..2e7c6c99 100644
--- a/OpenNest.Engine.Tests/Fill/OutlinePushTests.cs
+++ b/OpenNest.Engine.Tests/Fill/OutlinePushTests.cs
@@ -25,9 +25,6 @@ public class OutlinePushTests
private const double NotchWidth = 3;
private const double Edge = 0.25;
- // How far short of a wall a box push stops: the chord tolerance plus two Clipper grid units.
- private const double BoxMargin = SpacingOutline.ChordTolerance + 0.0002 + 1e-9;
-
private static SheetOutline NotchedSheet(IEnumerable> obstacles = null) =>
new(new[]
{
@@ -95,15 +92,17 @@ public class OutlinePushTests
return new Vector(sheet.X, sheet.Y);
}
- /// The edge review's verdict: the circumscribed material keeps the edge spacing
- /// from the outline and its obstacles, within the shared slack.
+ /// The edge review's outline test: the material keeps the edge spacing from the
+ /// outline and its obstacles, within the shared slack; what the circumscribed outline flags
+ /// is confirmed on the native contours.
private static bool KeepsTheOutline(Plate plate, Part part)
{
// The drawing's own material: a placed program can carry leads. No test here rotates a part.
var profile = new ShapeProfile(ConvertProgram.ToGeometry(part.BaseDrawing.Program).ForNesting().ToList());
var material = SpacingOutline.Build(profile, part.Location, 0);
var region = new PathsD { ClipperBridge.ToPath(material.Perimeter, positive: true) };
- return plate.Outline.Holds(region, Edge, Origin(plate), SpacingOutline.SpacingSlack);
+ return plate.Outline.Holds(region, () => NativeContours.Region(profile.Perimeter, part.Location),
+ Edge, Origin(plate), SpacingOutline.SpacingSlack);
}
[Fact]
@@ -181,18 +180,38 @@ public class OutlinePushTests
}
[Fact]
- public void ARoundPartStopsWhereTheEdgeReviewStillPasses()
+ public void ARoundPartRestsOnTheWallAsOnThePlateEdge()
{
- // The review circumscribes arcs, so a disc must stop that much short of the wall.
+ // The arc is slid as an arc and the review confirms on native contours: no chord gap.
var plate = MakePlate();
var mover = Add(plate, DiscProgram(1.5), 20, 1);
+ var moving = new List { mover };
Assert.True(KeepsTheOutline(plate, mover));
- Compactor.Push(new List { mover }, plate, PushDirection.Left);
+ Compactor.Push(moving, plate, PushDirection.Left);
- Assert.InRange(mover.BoundingBox.Left, NotchLength + Edge - 1e-6,
- NotchLength + Edge + SpacingOutline.ChordTolerance);
+ Assert.Equal(NotchLength + Edge, mover.BoundingBox.Left, 6);
Assert.True(KeepsTheOutline(plate, mover));
+ Assert.Equal(0, Compactor.Push(moving, plate, PushDirection.Left), 6);
+
+ // Down the wall to the plate's own edge, where the box test holds it: still clean.
+ Compactor.Push(moving, plate, PushDirection.Down);
+ Assert.Equal(Edge, mover.BoundingBox.Bottom, 6);
+ Assert.Equal(NotchLength + Edge, mover.BoundingBox.Left, 6);
+ Assert.True(KeepsTheOutline(plate, mover));
+ }
+
+ [Fact]
+ public void ARoundPartPastTheWallByMoreThanTheSlackFailsTheReview()
+ {
+ var plate = MakePlate();
+ var resting = Add(plate, DiscProgram(1.5), NotchLength + Edge, 0.25);
+ var within = Add(plate, DiscProgram(1.5), NotchLength + Edge - 0.0003, 0.25);
+ var past = Add(plate, DiscProgram(1.5), NotchLength + Edge - 0.001, 0.25);
+
+ Assert.True(KeepsTheOutline(plate, resting));
+ Assert.True(KeepsTheOutline(plate, within));
+ Assert.False(KeepsTheOutline(plate, past));
}
[Fact]
@@ -295,15 +314,12 @@ public class OutlinePushTests
Compactor.SettlePlacement(moving, plate, PushDirection.Left, PushDirection.Down,
boundingBoxesOnly: boundingBoxesOnly);
- // A box push stops a hair short of a wall; the geometry pushes then close it.
- var wall = NotchLength + Edge;
- Assert.InRange(copy.BoundingBox.Left, wall - 1e-6, wall + (boundingBoxesOnly ? BoxMargin : 1e-6));
+ Assert.Equal(NotchLength + Edge, copy.BoundingBox.Left, 6);
Assert.Equal(Edge, copy.BoundingBox.Bottom, 6);
Assert.True(KeepsTheOutline(plate, copy));
}
- // A circumscribed arc reaches past the part's bounding box, so a box resting on the wall
- // left the perimeter inside it and the following geometry push ran through the wall.
+ // A box push rests the box on the wall; the material in it must still be held there.
[Theory]
[InlineData(false)]
[InlineData(true)]
@@ -317,7 +333,7 @@ public class OutlinePushTests
Compactor.SettlePlacement(new List { disc }, plate, PushDirection.Left, PushDirection.Down,
boundingBoxesOnly: boundingBoxesOnly);
- Assert.InRange(disc.BoundingBox.Bottom, NotchWidth + Edge - 1e-6, NotchWidth + Edge + BoxMargin);
+ Assert.Equal(NotchWidth + Edge, disc.BoundingBox.Bottom, 6);
Assert.True(KeepsTheOutline(plate, disc), $"radius {radius}");
}
}
@@ -333,23 +349,23 @@ public class OutlinePushTests
Compactor.SettlePlacement(new List { obround }, plate, PushDirection.Left, PushDirection.Down,
boundingBoxesOnly: boundingBoxesOnly);
- Assert.InRange(obround.BoundingBox.Left, NotchLength + Edge - 1e-6, NotchLength + Edge + BoxMargin);
+ Assert.Equal(NotchLength + Edge, obround.BoundingBox.Left, 6);
Assert.True(KeepsTheOutline(plate, obround));
}
[Fact]
- public void BoxPushStopsShortOfTheWallSoTheNextGeometryPushIsHeld()
+ public void BoxPushRestsOnTheWallAndTheNextGeometryPushIsHeld()
{
var plate = MakePlate();
var mover = Add(plate, DiscProgram(1.5), 2, 12);
var moving = new List { mover };
Compactor.PushBoundingBox(moving, plate, PushDirection.Down);
- Assert.InRange(mover.BoundingBox.Bottom, NotchWidth + Edge + SpacingOutline.ChordTolerance,
- NotchWidth + Edge + BoxMargin);
+ Assert.Equal(NotchWidth + Edge, mover.BoundingBox.Bottom, 6);
+ Assert.True(KeepsTheOutline(plate, mover));
- var closed = Compactor.Push(moving, plate, PushDirection.Down);
- Assert.InRange(closed, 0, BoxMargin);
+ Assert.Equal(0, Compactor.Push(moving, plate, PushDirection.Down), 6);
+ Assert.Equal(0, Compactor.PushBoundingBox(moving, plate, PushDirection.Down), 6);
Assert.True(KeepsTheOutline(plate, mover));
}
diff --git a/OpenNest.Engine.Tests/Jobs/IrregularStockTests.cs b/OpenNest.Engine.Tests/Jobs/IrregularStockTests.cs
index b9f48f91..463b614b 100644
--- a/OpenNest.Engine.Tests/Jobs/IrregularStockTests.cs
+++ b/OpenNest.Engine.Tests/Jobs/IrregularStockTests.cs
@@ -183,6 +183,120 @@ public class IrregularStockTests
Assert.Empty(NestLayoutCheck.Violations(corner, fine));
}
+ // A disc turned 0.1 rad puts a vertex of its circumscribed outline about 0.0009 past its
+ // true bottom and top: on an outlined sheet that used to be a violation, on a rectangle not.
+ private const double Turned = 0.1;
+ private const double Radius = 1.5;
+
+ private static readonly Spacing Quarter = new(0.25, 0.25, 0.25, 0.25);
+
+ /// Disc centers resting on the Ell's usable edge at 0.25 edge spacing: the box's
+ /// bottom and left edges, and the arm's top (y = 24), an outline wall inside the box.
+ public static TheoryData OnTheUsableEdge => new()
+ {
+ { 20, 0.25 + Radius },
+ { 0.25 + Radius, 20 },
+ { 70, 23.75 - Radius },
+ };
+
+ private static NestJob DiscJob(SheetOutline outline) =>
+ new([new NestJobPart("disc", PartGeometrySnapshot.FromProgram(TestShapes.Disc(Radius)), 1)],
+ [Stock(outline, edge: Quarter)]);
+
+ private static NestJobResult DiscAt(NestJob job, double x, double y) =>
+ new(NestJobStatus.Complete, NestJobStopReason.Completed,
+ [new NestJobPlateResult(0, job.Plates[0], [new NestJobPlacement("disc", 0, x, y, Turned)])],
+ [new PartFulfillment("disc", 1, 1, 0)], [new StockUsage("drop", 1, 0)]);
+
+ [Theory]
+ [MemberData(nameof(OnTheUsableEdge))]
+ public void LayoutCheck_AcceptsARoundPartRestingOnTheUsableEdge(double x, double y)
+ {
+ var job = DiscJob(Ell());
+
+ Assert.Empty(NestLayoutCheck.Violations(job, DiscAt(job, x, y)));
+ }
+
+ [Fact]
+ public void LayoutCheck_RejectsARoundPartPastTheUsableEdge()
+ {
+ // 0.001 into the edge spacing of the arm's top: the true material is past the edge.
+ var job = DiscJob(Ell());
+
+ var violation = Assert.Single(NestLayoutCheck.Violations(job, DiscAt(job, 70, 23.751 - Radius)));
+ Assert.Contains("outline", violation);
+ }
+
+ [Theory]
+ [MemberData(nameof(OnTheUsableEdge))]
+ public void Runner_AcceptsARoundCandidateRestingOnTheUsableEdge(double x, double y)
+ {
+ var job = DiscJob(Ell());
+
+ NestJobValidator.ValidateCandidate(new PlateCandidate([new NestJobPlacement("disc", 0, x, y, Turned)]),
+ job.Plates[0], new Dictionary { ["disc"] = 1 }, job.Parts.ToDictionary(p => p.Id));
+ }
+
+ [Fact]
+ public void Runner_RefusesARoundCandidatePastTheUsableEdge()
+ {
+ var job = DiscJob(Ell());
+ var candidate = new PlateCandidate([new NestJobPlacement("disc", 0, 70, 23.751 - Radius, Turned)]);
+
+ var exception = Assert.Throws(() => NestJobValidator.ValidateCandidate(
+ candidate, job.Plates[0], new Dictionary { ["disc"] = 1 }, job.Parts.ToDictionary(p => p.Id)));
+ Assert.Contains("usable stock area", exception.Message);
+ }
+
+ [Fact]
+ public void RunnerAndLayoutCheck_AgreeOnARoundPartAtASlantedEdge()
+ {
+ // The chamfer runs from (72, 48) to (96, 24); its middle is (84, 36). The disc backs off
+ // along the normal from resting on the usable edge (0.25 inside), turned every which way:
+ // no straight box edge helps here, so both checks must reach one verdict pose by pose.
+ var job = DiscJob(Chamfered());
+ var parts = job.Parts.ToDictionary(p => p.Id);
+
+ bool Runner(NestJobPlacement pose)
+ {
+ try
+ {
+ NestJobValidator.ValidateCandidate(new PlateCandidate([pose]), job.Plates[0],
+ new Dictionary { ["disc"] = 1 }, parts);
+ return true;
+ }
+ catch (InvalidOperationException)
+ {
+ return false;
+ }
+ }
+
+ NestJobPlacement Pose(double back, double turn)
+ {
+ var d = (0.25 + Radius + back) / System.Math.Sqrt(2);
+ return new NestJobPlacement("disc", 0, 84 - d, 36 - d, turn);
+ }
+
+ bool Layout(NestJobPlacement pose) => NestLayoutCheck.Violations(job, new NestJobResult(
+ NestJobStatus.Complete, NestJobStopReason.Completed,
+ [new NestJobPlateResult(0, job.Plates[0], [pose])],
+ [new PartFulfillment("disc", 1, 1, 0)], [new StockUsage("drop", 1, 0)])).Count == 0;
+
+ for (var k = -8; k <= 8; k++)
+ for (var t = 0; t < 12; t++)
+ {
+ var pose = Pose(k * 0.00005, t * 0.137);
+ Assert.True(Runner(pose) == Layout(pose), $"back {k * 0.00005}, turn {t * 0.137}");
+ }
+
+ // Clear of the edge by a grid unit both accept; 0.001 past it both refuse.
+ for (var t = 0; t < 12; t++)
+ {
+ Assert.True(Runner(Pose(0.0001, t * 0.137)) && Layout(Pose(0.0001, t * 0.137)), $"turn {t * 0.137}");
+ Assert.False(Runner(Pose(-0.001, t * 0.137)) || Layout(Pose(-0.001, t * 0.137)), $"turn {t * 0.137}");
+ }
+ }
+
[Fact]
public void Runner_RefusesACandidateOutsideTheOutline()
{
diff --git a/OpenNest.Engine/Jobs/InteractiveOutline.cs b/OpenNest.Engine/Jobs/InteractiveOutline.cs
index 552b7a76..364abdff 100644
--- a/OpenNest.Engine/Jobs/InteractiveOutline.cs
+++ b/OpenNest.Engine/Jobs/InteractiveOutline.cs
@@ -13,12 +13,12 @@ namespace OpenNest.Engine.Jobs;
/// work area stays the pushes' own box test; these walls add only what the outline takes away
/// from it, so a rectangular sheet has none and its pushes are unchanged.
///
-/// A moving part is measured as the edge review measures it against an outline: the
-/// circumscribed perimeter () of its clean drawing material, without
-/// leads, so a push that stops at a wall rests exactly where that review still passes. A box
-/// push stops short, so the perimeter of the part in that box is still
-/// clear of the wall. A part that already lies in a wall, deeper than the review's slack, is not
-/// held by it, like a part already overlapping another: it can be pushed back out.
+/// A moving part is measured by its true material, as the edge review confirms it against an
+/// outline: the perimeter of its clean drawing material, without leads, slid with its arcs as
+/// arcs, so a round part rests on a wall as it rests on the plate edge and that review passes.
+/// A box push rests the box on the wall. A part that already lies in a wall, deeper than the
+/// review's slack, is not held by it, like a part already overlapping another: it can be
+/// pushed back out.
///
///
internal sealed class InteractiveOutline
@@ -29,11 +29,6 @@ internal sealed class InteractiveOutline
/// plate edge. The box test already holds that edge.
private static readonly double EdgeClip = 2 * System.Math.Pow(10, -ClipperBridge.Precision);
- /// How far a part's circumscribed perimeter can reach past its bounding box: the
- /// chord tolerance, and the grid the perimeter is built on. A box resting on a wall without
- /// it leaves the perimeter inside the wall, where the next geometry push would not be held.
- private static readonly double BoxMargin = SpacingOutline.ChordTolerance + EdgeClip;
-
private static readonly InteractiveOutline None = new(new List());
private readonly List walls;
@@ -88,27 +83,27 @@ internal sealed class InteractiveOutline
///
/// The shorter of and how far travels
- /// along before its circumscribed perimeter meets a wall.
+ /// along before the perimeter of its material meets a wall.
///
public double Travel(Part moving, Vector direction, double distance)
{
if (walls.Count == 0)
return distance;
- var reach = moving.BoundingBox.Offset(BoxMargin);
- return Travel(reach, () => PerimeterLines(moving), direction, distance);
+ // The material lies within the placed program's bounds, leads included.
+ return Travel(moving.BoundingBox, () => Material(moving), direction, distance);
}
/// As for a part's bounding box: the
- /// box pushes move a part as its box, which stops short of a wall.
+ /// box pushes move a part as its box, which rests on a wall.
public double Travel(Box moving, Vector direction, double distance)
{
if (walls.Count == 0)
return distance;
- var grown = moving.Offset(BoxMargin);
- return Travel(grown, () => BoxLines(grown), direction, distance);
+ return Travel(moving, () => (BoxLines(moving), new PathsD { BoxPath(moving) }), direction, distance);
}
- private double Travel(Box reach, Func> movingLines, Vector direction, double distance)
+ private double Travel(Box reach, Func<(List Boundary, PathsD Region)> material, Vector direction,
+ double distance)
{
var opposite = -direction;
List lines = null;
@@ -124,12 +119,12 @@ internal sealed class InteractiveOutline
if (!SpatialQuery.PerpendicularOverlap(reach, wall.Bounds, direction))
continue;
- lines ??= movingLines();
+ if (lines == null)
+ (lines, region) = material();
if (lines.Count == 0)
return distance;
// Already in this wall: the slide kernel answers for boundaries that start apart.
- region ??= new PathsD { new PathD(lines.Select(line => ((Line)line).StartPoint).Select(p => new PointD(p.X, p.Y))) };
if (wall.Core.Count > 0 && Clipper.Intersect(region, wall.Core, FillRule.NonZero, ClipperBridge.Precision)
.Sum(path => System.Math.Abs(Clipper.Area(path))) > 0)
continue;
@@ -189,11 +184,12 @@ internal sealed class InteractiveOutline
}
/// The part's material perimeter as the edge review takes it: the drawing's clean
- /// material at the part's pose (no leads, seam overcut trimmed), arcs circumscribed at the
- /// spacing outline's chord tolerance. Empty without a closed perimeter.
- private static List PerimeterLines(Part part)
+ /// material at the part's pose (no leads, seam overcut trimmed). The boundary is its native
+ /// lines and arcs, for the slide; the region is what the review confirms an outline with
+ /// (). Empty without a closed perimeter.
+ private static (List Boundary, PathsD Region) Material(Part part)
{
- var lines = new List();
+ var boundary = new List();
ShapeProfile profile;
try
{
@@ -201,26 +197,34 @@ internal sealed class InteractiveOutline
}
catch (ArgumentException)
{
- return lines;
+ return (boundary, new PathsD());
}
- var outline = profile == null ? null : SpacingOutline.Build(profile, part.Location, 0);
- if (outline?.Perimeter != null)
- AddLoop(ClipperBridge.ToPath(outline.Perimeter, positive: true), lines);
- return lines;
+ if (profile?.Perimeter == null)
+ return (boundary, new PathsD());
+ // The profile is the drawing's, at the origin: move copies, never its entities.
+ foreach (var entity in profile.Perimeter.Entities)
+ {
+ var moved = entity.Clone();
+ moved.Offset(part.Location);
+ boundary.Add(moved);
+ }
+ return (boundary, NativeContours.Region(profile.Perimeter, part.Location));
}
private static List BoxLines(Box box)
{
var lines = new List(4);
- AddLoop(new PathD
- {
- new PointD(box.Left, box.Bottom), new PointD(box.Right, box.Bottom),
- new PointD(box.Right, box.Top), new PointD(box.Left, box.Top),
- }, lines);
+ AddLoop(BoxPath(box), lines);
return lines;
}
+ private static PathD BoxPath(Box box) => new()
+ {
+ new PointD(box.Left, box.Bottom), new PointD(box.Right, box.Bottom),
+ new PointD(box.Right, box.Top), new PointD(box.Left, box.Top),
+ };
+
/// is the wall less the edge review's slack on every side: a
/// part resting on the wall never reaches it, a part lying in the wall does.
private sealed record Wall(List Entities, Box Bounds, PathsD Core);
diff --git a/OpenNest.Engine/Jobs/NestJobPlacementValidator.cs b/OpenNest.Engine/Jobs/NestJobPlacementValidator.cs
index 61dc06af..21594ab6 100644
--- a/OpenNest.Engine/Jobs/NestJobPlacementValidator.cs
+++ b/OpenNest.Engine/Jobs/NestJobPlacementValidator.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using Clipper2Lib;
using OpenNest.Engine.Jobs.Placement;
using OpenNest.Geometry;
@@ -69,6 +68,12 @@ internal static class NestJobPlacementValidator
);
poses.Add((geometries[placement.PartId], placement));
spaced.Add(null);
+ // An outlined sheet is judged by the layout check's own test, so both accept the same
+ // poses. A rectangle needs no outline prepared for it.
+ if (stock.Outline != null && !NestLayoutCheck.InsideOutline(Spaced(placed.Count), stock, Epsilon))
+ throw new InvalidOperationException(
+ "Candidate placement falls outside the usable stock area."
+ );
for (var k = 0; k < placed.Count; k++)
{
var other = placed[k];
@@ -121,12 +126,7 @@ internal static class NestJobPlacementValidator
foreach (var cutout in shape.Cutouts)
if (!FitsWorkArea(cutout, workArea))
return false;
- if (stock.Outline == null)
- return true;
- // The circumscribed perimeter must lie in the outline's usable area; holes are inside it.
- var perimeter = ClipperBridge.ToPath(
- ClipperBridge.Flatten(shape.Perimeter, NestTolerances.ValidationOutline, circumscribe: true), positive: true);
- return stock.OutlineHolds(new PathsD { perimeter }, Epsilon);
+ return true;
}
private static bool FitsWorkArea(Shape contour, Box workArea)
diff --git a/OpenNest.Engine/Jobs/NestLayoutCheck.cs b/OpenNest.Engine/Jobs/NestLayoutCheck.cs
index d0395976..a986d241 100644
--- a/OpenNest.Engine/Jobs/NestLayoutCheck.cs
+++ b/OpenNest.Engine/Jobs/NestLayoutCheck.cs
@@ -206,6 +206,8 @@ public static class NestLayoutCheck
InflateBy = InflationFor(spacing);
}
+ internal ShapeProfile Profile => profile;
+ internal Vector Location => location;
internal SpacingOutline Raw { get; }
internal double Spacing { get; }
internal double InflateBy { get; }
@@ -216,6 +218,23 @@ public static class NestLayoutCheck
internal NativeContours Native => native ??= NativeContours.Of(profile, location);
}
+ ///
+ /// The layout check's outline verdict for a prepared part on : true
+ /// on a rectangular sheet, else whether its material lies in the usable area within
+ /// . The spacing outline's perimeter is the candidate and
+ /// confirms a failure, exactly as
+ /// judges a placed part, so the whole-job
+ /// runner validates candidates with it. A part without a perimeter is not held.
+ ///
+ internal static bool InsideOutline(PreparedPlacement a, NestPlateStock stock, double slack) =>
+ stock.Outline == null
+ || (a.Raw != null && InsideOutline(stock, a.Raw, a.Profile, a.Location, slack));
+
+ private static bool InsideOutline(NestPlateStock stock, SpacingOutline material, ShapeProfile profile,
+ Vector location, double slack) =>
+ stock.OutlineHolds(new PathsD { ClipperBridge.ToPath(material.Perimeter, positive: true) },
+ () => NativeContours.Region(profile.Perimeter, location), slack);
+
private static ShapeProfile Transform(JobPartGeometry geometry, double rotation)
{
var shapes = new[] { geometry.Perimeter }.Concat(geometry.Cutouts);
@@ -549,11 +568,11 @@ public static class NestLayoutCheck
continue;
}
- // An outlined sheet: the circumscribed material must lie in the usable area, which
- // keeps the largest edge spacing from every edge and obstacle, within the same slack.
- if (stock != null && Outline(part, 0) is { } material
- && !stock.OutlineHolds(new PathsD { ClipperBridge.ToPath(material.Perimeter, positive: true) },
- NestTolerances.WorkAreaSlack))
+ // An outlined sheet: the material must lie in the usable area, which keeps the largest
+ // edge spacing from every edge and obstacle, within the same slack. The outline
+ // circumscribes arcs, so what it flags is confirmed on the native contours.
+ if (stock != null && Profile(part) is { } profile && Outline(profile, part.Location, 0) is { } material
+ && !InsideOutline(stock, material, profile, part.Location, NestTolerances.WorkAreaSlack))
{
result.Add(
$"'{DisplayName(part, requirements)}' at ({part.Location.X:F2},{part.Location.Y:F2}) falls outside the outline "
diff --git a/OpenNest.Engine/Jobs/NestPlateStock.cs b/OpenNest.Engine/Jobs/NestPlateStock.cs
index 2c67801b..0b9ca26e 100644
--- a/OpenNest.Engine/Jobs/NestPlateStock.cs
+++ b/OpenNest.Engine/Jobs/NestPlateStock.cs
@@ -149,6 +149,16 @@ public sealed class NestPlateStock
public bool OutlineHolds(PathsD region, double slack) =>
Outline == null || Outline.Holds(region, OutlineInset, PlacementOrigin, slack);
+ ///
+ /// for a part's material:
+ /// (the circumscribed perimeter) is the candidate test, and a failure is confirmed on
+ /// , the perimeter's , as
+ /// describes.
+ /// The layout check and the runner's candidate validation both judge an outline with it.
+ ///
+ public bool OutlineHolds(PathsD outline, Func native, double slack) =>
+ Outline == null || Outline.Holds(outline, native, OutlineInset, PlacementOrigin, slack);
+
/// Available physical sheets: null is unlimited, zero is legal but unavailable.
public int? Quantity { get; }
public double PartSpacing { get; }
diff --git a/OpenNest.Tests/Diagnostics/PlateEdgeReviewTests.cs b/OpenNest.Tests/Diagnostics/PlateEdgeReviewTests.cs
index df857ef9..d51e91cf 100644
--- a/OpenNest.Tests/Diagnostics/PlateEdgeReviewTests.cs
+++ b/OpenNest.Tests/Diagnostics/PlateEdgeReviewTests.cs
@@ -167,6 +167,54 @@ public class PlateEdgeReviewTests
Assert.Empty(Find(report, PostVerificationKind.EdgeSpacing));
}
+ // The outline test circumscribes arcs by up to 0.001, more than the slack, so a disc whose
+ // true bounds rest on the work-area edge used to warn on an outlined sheet only.
+ [Theory]
+ [InlineData(20, 0.25)] // bottom edge of the sheet's box
+ [InlineData(0.25, 10)] // left edge
+ [InlineData(20, 23.75)] // top edge
+ [InlineData(56.75, 10)] // right edge
+ [InlineData(1, 3.25)] // the notch's top, an outline wall inside the box
+ [InlineData(6.25, 0.25)] // the notch's side and the bottom edge at once
+ public void OutlinedSheet_RoundPartRestingOnTheUsableEdge_IsClear(double x, double y)
+ {
+ var report = PostVerificationAnalyzer.Analyze(Notched(Edges(0.25), Disc(x, y)));
+
+ Assert.Empty(Find(report, PostVerificationKind.OffPlate));
+ Assert.Empty(Find(report, PostVerificationKind.EdgeSpacing));
+ }
+
+ [Fact]
+ public void OutlinedSheet_RoundPartOnTheSheetEdge_IsNotOffPlate()
+ {
+ // No edge spacing: the disc rests on the sheet's own edge and on the notch's top.
+ var report = PostVerificationAnalyzer.Analyze(Notched(new Spacing(), Disc(20, 0), Disc(1, 3)));
+
+ Assert.Empty(Find(report, PostVerificationKind.OffPlate));
+ Assert.Empty(Find(report, PostVerificationKind.EdgeSpacing));
+ }
+
+ [Fact]
+ public void OutlinedSheet_RoundPartPastTheUsableEdge_StillWarns()
+ {
+ // Within the slack passes; 0.001 into the notch's edge spacing does not.
+ var within = PostVerificationAnalyzer.Analyze(Notched(Edges(0.25), Disc(1, 3.25 - 0.0003)));
+ Assert.Empty(Find(within, PostVerificationKind.EdgeSpacing));
+
+ var past = PostVerificationAnalyzer.Analyze(Notched(Edges(0.25), Disc(1, 3.249)));
+ Assert.Empty(Find(past, PostVerificationKind.OffPlate));
+ var finding = Assert.Single(Find(past, PostVerificationKind.EdgeSpacing));
+ Assert.Contains("inside the 0.250 edge spacing of the plate's outline", finding.Message);
+
+ var beside = PostVerificationAnalyzer.Analyze(Notched(Edges(0.25), Disc(6.249, 0.25)));
+ Assert.Single(Find(beside, PostVerificationKind.EdgeSpacing));
+
+ // 0.001 into the missing corner itself is off the plate.
+ var off = PostVerificationAnalyzer.Analyze(Notched(new Spacing(), Disc(1, 2.999)));
+ var offPlate = Assert.Single(Find(off, PostVerificationKind.OffPlate));
+ Assert.Contains("lies outside the plate's outline", offPlate.Message);
+ }
+
[Fact]
public void CutOffParts_AreExempt()
{
@@ -214,4 +262,20 @@ public class PlateEdgeReviewTests
private static Part Square(double x, double y, double size, string name = "square") =>
new(new Drawing(name, MakeSquareProgram(0, 0, size)), new Vector(x, y));
+
+ /// A radius 1.5 disc whose bounds start at (x, y).
+ private static Part Disc(double x, double y) =>
+ new(new Drawing("disc", MakeCircleProgram(1.5, 1.5, 1.5)), new Vector(x, y));
+
+ /// A 60 x 27 sheet missing a 6 x 3 rectangle at its lower-left corner.
+ private static Nest Notched(Spacing edges, params Part[] parts)
+ {
+ var nest = NestWith(edges, parts);
+ nest.Plates[0].Outline = new SheetOutline(new[]
+ {
+ new Vector(6, 0), new Vector(60, 0), new Vector(60, 27),
+ new Vector(0, 27), new Vector(0, 3), new Vector(6, 3),
+ });
+ return nest;
+ }
}
diff --git a/docs/irregular-stock.md b/docs/irregular-stock.md
index c995c073..f2746ad2 100644
--- a/docs/irregular-stock.md
+++ b/docs/irregular-stock.md
@@ -31,9 +31,9 @@ Drawing an outline in the plate view and taking the leftover of a cut plate are
|---|---|
| Irregular engine (and Default through it) | Fills the outline: the stock's usable material (outline less obstacles, eroded by the outline inset below) is the `FrontierPacker`'s `PackBoundary`, the same boundary the cutout packer uses, so every orientation's free region starts inside it |
| Rectangles, Circles, FlatBar, the fill strategies (Lattice, Strip, remnants) | Place nothing on an outlined sheet; Default then keeps Irregular's layout. `PlateFillService` throws `PlateFillService.Refusal(plate)` for an outlined plate; every caller checks it first: the desktop's Fill (Ctrl+F on a picked-up part) and Fill Area put the message in the status bar and add nothing, Pattern Tile offers a new plate only, the MCP fill/pack tools return it as an `Error:` result, and the console exits 2 with it unless `--autonest` is given |
-| Layout check and the runner's candidate validation | A part's circumscribed material must lie inside the usable area, within the shared work-area slack; a part in a missing corner or over an obstacle is a violation ("falls outside the outline ... or over one of its obstacles"). The area budget is the usable area |
+| Layout check and the runner's candidate validation | A part's material must lie inside the usable area; a part in a missing corner or over an obstacle is a violation ("falls outside the outline ... or over one of its obstacles"). The spacing outline, which circumscribes arcs by up to 0.001, finds the candidates and the part's native contour confirms them (`SheetOutline.Holds` with `NativeContours.Region`: arcs circumscribed at 0.000025, clipped to the part's true bounds), as for part spacing, so a round part resting on an edge passes as a square one does. The runner calls the layout check's own test (`NestLayoutCheck.InsideOutline`), so the two accept the same poses. The area budget is the usable area |
| Edge spacing | The outline is eroded by the **largest** of the four edge spacings (`NestPlateStock.OutlineInset`), so no outline edge is closer to a part than the rectangle's own sides would be. The rectangular work area still applies and is never larger than that erosion |
-| Push, clone push placement, settling | A pushed part stops at the edge of the usable area as it stops at the work-area edge: the unusable part of the work area (a missing corner, an obstacle, each grown by the outline inset) is a wall for `Compactor`'s plate pushes (`InteractiveOutline`). The part is measured as the edge review measures it, by the circumscribed perimeter of its clean material (no leads), so it rests where that review still passes. A bounding-box push (Ctrl-click clone placement, the coarse pass of a settle) stops the box 0.0012 short of a wall, because that perimeter reaches past the box by up to the chord tolerance. A part already lying in a wall, deeper than the review's slack, is not held by it and can be pushed back out; with uneven edge spacing the walls join into one, so such a part is held by none of them |
+| Push, clone push placement, settling | A pushed part stops at the edge of the usable area as it stops at the work-area edge: the unusable part of the work area (a missing corner, an obstacle, each grown by the outline inset) is a wall for `Compactor`'s plate pushes (`InteractiveOutline`). The part is measured by the perimeter of its clean material (no leads) with its arcs slid as arcs, so a round part rests on a wall exactly as it rests on the plate edge, where the edge review passes. A bounding-box push (Ctrl-click clone placement, the coarse pass of a settle) rests the box on the wall. A part already lying in a wall, deeper than the review's slack, is not held by it and can be pushed back out; with uneven edge spacing the walls join into one, so such a part is held by none of them |
| Nudge, drag, Expand Spacing, Fix Spacing | Do not stop at the outline: the layout check reports a part they leave outside it |
| Clamps | Unchanged: the rail is resolved for the bounding box, zones are keep-outs as before |
| Support bed | Unchanged: it is fixed to the machine and reports contacts under material |
@@ -66,6 +66,8 @@ snapshots go through the same writer and reader, so a restore rebuilds the outli
imported arcs and exactly on straight edges. Outlines imported before straight edges were
kept exactly sit 0.001 inside every edge (a 60 x 27 sheet reads 59.998 x 26.998); import the
outline again to get the drawn size.
-- The edge review circumscribes arcs, so a round part pushed against the sheet's own box edge
- (held by the bounding-box work area, measured on the part's true bounds) can read up to the
- chord tolerance inside the outline's edge spacing. Against an outline wall it stops clear.
+- The layout check and the runner judge an outline on Clipper's 0.0001 grid with a slack
+ below it. A round part resting exactly on a slanted or rounded edge of the usable area can
+ fail them by one grid unit, depending on where its confirming contour's vertices fall, and
+ passes from 0.0001 clear; on an edge parallel to the sheet's box its true bounds decide, so
+ it passes resting on it. The pre-post edge review allows 0.0005 and passes all of these.
diff --git a/docs/post-verification.md b/docs/post-verification.md
index b398a274..8503ecb1 100644
--- a/docs/post-verification.md
+++ b/docs/post-verification.md
@@ -134,7 +134,10 @@ shows the first three check categories, even when there are no findings:
outside the plate's work area, so closer to an edge than that side's edge spacing, or, on
an outlined sheet, closer than the largest edge spacing to the outline or an obstacle.
This is the bound Auto Nest's layout check applies, so a layout it accepted stays clear;
- shortfalls up to `SpacingSlack` pass. Leads may run into the edge spacing. The finding
+ shortfalls up to `SpacingSlack` pass. An outline is tested on the spacing outline and what
+ that flags is confirmed on the part's native contour (`NativeContours.Region`), as for part
+ spacing, so a round part resting on the usable edge is clear on an outlined sheet as it is
+ on a rectangle. Leads may run into the edge spacing. The finding
says the part is outside the work area and gives the gap and the side's spacing, as in
`'name' is outside the work area: 0.200 from the plate's left edge, inside its 0.500 edge
spacing.` (`PostVerificationKind.EdgeSpacing`). Zero edge spacing allows contact with the edge.