[ANN] SimplexCellLists.jl v0.3.0: Fast and accurate triangle distances

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

Annoyingly (at least on my Zen 5 CPU) LLVM is really bad at doing SIMD gathers, so it is very tricky to get close to the ideal performance numbers in real tasks. You can see an example of the elaborate workarounds needed to prevent LLVM from doing bad optimizations here: SimplexCellLists.jl/src/neighbor-lists-grid.jl at c488234675107ae38f1a91f3926bad180ff338eb · medyan-dev/SimplexCellLists.jl · GitHub