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();