fix: correct FMM source propagation#250
Conversation
Store tentative source-adjacent distances when queueing candidates so triangle updates do not read infinities before source vertices are finalized.
Use the opposite edge lengths in the barycentric squared-distance cross terms and clamp tiny negative roundoff before taking square roots.
Track source labels through FMM candidates so triangle updates do not combine distances from unrelated source branches. Allow updates across explicit source-base edges from edge/face sources and signed curve segments so valid source support edges still initialize adjacent triangles.
|
Thanks for opening a PR! I agree with the fixes around line 211 for the squared-distance-to-triangle-vertex calculations, and clamping before The new Just to clarify the main new things happening in this PR:
I just ran your code on a few examples, and it seems to work well on a few toy examples. Thanks again for contributing. |
|
Hi @nzfeng ! Thank you for the work you've put into this algorithm. It's been immensely useful for the work we're doing! Regarding your comments:
Hopefully this helps explain the PR a little better but if you would like for us to set up a meeting for me to show you more visually, just let me know! |

Summary
This PR fixes several Fast Marching Method distance initialization and propagation issues for vertex, edge, face, and curve sources.
Details
FMM source initialization
FMMDistance()now stores tentative distances for source-adjacent vertices when they are enqueued.Previously, triangle updates could read
infinityfor vertices that had been queued from source geometry but had not yet been finalized. Recording the tentative distance at enqueue time ensures that adjacent triangle updates operate on the intended provisional source distances.Face-source distance correction
Face-source initialization now uses the correct opposite edge lengths in the barycentric squared-distance cross terms.
This PR also clamps tiny negative roundoff error before calling
sqrt(). This prevents invalid source-to-vertex distances and avoids numerical NaNs caused by near-zero negative values.Source-branch shortcut prevention
The FMM priority queue now carries a source label with each candidate distance.
Triangle updates only combine distances from the same source branch unless the update crosses an explicit source support edge. This prevents unrelated source branches from being combined during propagation, which could otherwise create artificial shortcuts through the mesh.
Explicit source-base edges are recorded for:
This preserves valid source-local initialization while preventing unrelated branches from collapsing into incorrect shorter paths.
This was the most significant error addressed by the PR. The images below show the issue and the corrected behavior:
There is still some deviation along the diagonal in the post-fix result. That deviation appears to come from the marching triangles extraction step and the underlying distance field, rather than from the FMM propagation bug fixed here. I plan to address that separately in a follow-up PR.
Impact