From c21f687987d394e31576bbbdcf94f239013fddad Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Tue, 6 Oct 2026 00:03:24 -0400 Subject: [PATCH] fix(cutting): never treat an extent with a nonfinite bound as separated IsSeparatedFrom promised that NaN bounds are never separated, but a finite axis could still compare as separated when the other axis held NaN. Program reading already refuses nonfinite coordinates, so no public path was affected; the helper now checks every bound and the margin are finite before comparing, which also covers the empty extent of an incomplete material snapshot. --- .../Diagnostics/PostVerificationGeometry.cs | 13 +++++++++---- .../CuttingPlanning/NearbyMaterialCheckTests.cs | 10 ++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/OpenNest.Core/Diagnostics/PostVerificationGeometry.cs b/OpenNest.Core/Diagnostics/PostVerificationGeometry.cs index c8aeda7..0711cc3 100644 --- a/OpenNest.Core/Diagnostics/PostVerificationGeometry.cs +++ b/OpenNest.Core/Diagnostics/PostVerificationGeometry.cs @@ -27,11 +27,16 @@ internal static class PostVerificationGeometry /// /// True only when the extents are farther apart than on some axis, - /// so nothing inside one can touch or enter the other. NaN bounds are never separated. + /// so nothing inside one can touch or enter the other. An extent with any nonfinite bound + /// (including the empty one) is never separated. /// - internal bool IsSeparatedFrom(Extent other, double margin) => - MaxX + margin < other.MinX || other.MaxX + margin < MinX - || MaxY + margin < other.MinY || other.MaxY + margin < MinY; + internal bool IsSeparatedFrom(Extent other, double margin) => IsFinite && other.IsFinite + && double.IsFinite(margin) + && (MaxX + margin < other.MinX || other.MaxX + margin < MinX + || MaxY + margin < other.MinY || other.MaxY + margin < MinY); + + private bool IsFinite => double.IsFinite(MinX) && double.IsFinite(MinY) + && double.IsFinite(MaxX) && double.IsFinite(MaxY); } internal static void Validate(Vector point) diff --git a/OpenNest.Tests/CuttingPlanning/NearbyMaterialCheckTests.cs b/OpenNest.Tests/CuttingPlanning/NearbyMaterialCheckTests.cs index a9455d8..15db0d8 100644 --- a/OpenNest.Tests/CuttingPlanning/NearbyMaterialCheckTests.cs +++ b/OpenNest.Tests/CuttingPlanning/NearbyMaterialCheckTests.cs @@ -145,6 +145,16 @@ public class NearbyMaterialCheckTests Assert.Contains("uncertain", result.Reason); } + [Fact] + public void ExtentWithANaNBound_IsNeverSeparated() + { + var partial = new PostVerificationGeometry.Extent(double.NaN, 0, double.NaN, 1); + var other = new PostVerificationGeometry.Extent(0, 4, 1, 5); + + Assert.False(partial.IsSeparatedFrom(other, 1e-6)); + Assert.False(other.IsSeparatedFrom(partial, 1e-6)); + } + private static Program CleanCircle(double radius) { var p = new Program();