fix: use chain tolerance for shape building to handle DXF endpoint gaps

DXF files can have endpoint gaps at entity junctions that fall right at
the floating-point boundary of Tolerance.Epsilon (0.00001). This caused
shapes to not close, resulting in 0 area and 0% utilization in Best-Fit.

Added ChainTolerance (0.0001) for endpoint chaining in GetConnected and
Shape.IsClosed, keeping the tighter Epsilon for geometric precision.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 08:37:39 -04:00
parent 9f84357c34
commit d0d334e734
3 changed files with 16 additions and 7 deletions

View File

@@ -26,6 +26,7 @@ namespace OpenNest.Geometry
if (Entities.Count == 0)
return false;
var tol = Math.Tolerance.ChainTolerance;
var first = Entities[0];
Vector firstStartPoint;
Vector firstEndPoint;
@@ -65,7 +66,7 @@ namespace OpenNest.Geometry
case EntityType.Arc:
var arc = (Arc)geo;
if (arc.StartPoint() != endpt)
if (arc.StartPoint().DistanceTo(endpt) > tol)
return false;
endpt = arc.EndPoint();
@@ -77,7 +78,7 @@ namespace OpenNest.Geometry
case EntityType.Line:
var line = (Line)geo;
if (line.StartPoint != endpt)
if (line.StartPoint.DistanceTo(endpt) > tol)
return false;
endpt = line.EndPoint;
@@ -112,7 +113,7 @@ namespace OpenNest.Geometry
return false;
}
return lastEndPoint == firstStartPoint;
return lastEndPoint.DistanceTo(firstStartPoint) <= tol;
}
/// <summary>