mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-06 16:22:10 -04:00
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.
This commit is contained in:
1 parent
c1c8d5fc36
commit
c21f687987
2 files changed
+19
-4
No files matched your search
@@ -27,11 +27,16 @@ internal static class PostVerificationGeometry
|
||||
|
||||
/// <summary>
|
||||
/// True only when the extents are farther apart than <paramref name="margin"/> 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.
|
||||
/// </summary>
|
||||
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)
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user