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

**URL:** <https://discourse.julialang.org/t/ann-simplexcelllists-jl-v0-3-0-fast-and-accurate-triangle-distances/140376>\
**Category:** Package Announcements\
**Created:** [October 30, 2026, 9:00pm UTC](https://discourse.julialang.org/t/ann-simplexcelllists-jl-v0-3-0-fast-and-accurate-triangle-distances/140376 "2026-10-30T21:00:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nhz2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nhz2/32/44428_2.png) [@nhz2](https://discourse.julialang.org/u/nhz2)\
**Post date:** [October 30, 2026, 9:00pm UTC](https://discourse.julialang.org/t/ann-simplexcelllists-jl-v0-3-0-fast-and-accurate-triangle-distances/140376/1 "2026-10-30T21:00:48Z")

</div>

[SimplexCellLists.jl](https://github.com/medyan-dev/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](https://github.com/nhz2/line-segment-triangle-distance-AI-proofs) 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

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/f/1f99d504864e99e1c8033687593df63c0dcf4357.png)

### Triangle to Triangle

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/e/0eda6129e21f8252ec5364767bbf6fcb1adb85a4.png)

Benchmark code is in [GitHub - nhz2/line-segment-triangle-distance-AI-proofs: AI proofs for SimplexCellLists.jl · GitHub](https://github.com/nhz2/line-segment-triangle-distance-AI-proofs)

---

<div class="post-metadata">

**Author:** ![nhz2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nhz2/32/44428_2.png) [@nhz2](https://discourse.julialang.org/u/nhz2)\
**Post date:** [October 30, 2026, 10:04pm UTC](https://discourse.julialang.org/t/ann-simplexcelllists-jl-v0-3-0-fast-and-accurate-triangle-distances/140376/2 "2026-10-30T22:04:10Z")

</div>

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](https://github.com/medyan-dev/SimplexCellLists.jl/blob/c488234675107ae38f1a91f3926bad180ff338eb/src/neighbor-lists-grid.jl#L212-L217)
