SimplexCellLists.jl has a dist_sqr function for calculating the closest distance between a pair of points, line segments, or triangles in 3D.
Recently while reviewing the package, Claude found some edge cases where my previous algorithm was extremely inaccurate due to floating point rounding errors getting amplified.
After many iterations playing rounding error and underflow whack-a-mole with Claude, the distance functions are now extremely accurate, fast, and support SIMD.jl
For what it is worth GitHub - nhz2/line-segment-triangle-distance-AI-proofs: AI proofs for SimplexCellLists.jl · GitHub contains an AI generated lean proof of a error bound. The results are accurate in both Float32 and Float64: with ℓ the
largest absolute coordinate, √d² is within 64*eps(T)*ℓ + floatmin(T)^(1/4)
of the exact minimum distance, for coordinates below floatmax(T)^(1/4)/4 (1e9 for Float32, 3e76 for Float64).
Here are benchmarks of the Float64 distance function compared to CGAL and Geometric Tools. The times are for inputs lined up nicely in memory for SIMD.jl to do its thing.
Line Segment to Line Segment
Triangle to Triangle
Benchmark code is in GitHub - nhz2/line-segment-triangle-distance-AI-proofs: AI proofs for SimplexCellLists.jl · GitHub

