Deltares / xugrid

Xarray and unstructured grids
https://deltares.github.io/xugrid/
MIT License
65 stars 8 forks source link

Improve and expose `snap_nodes` #282

Closed Huite closed 3 months ago

Huite commented 3 months ago

I wrote snap_nodes a while ago: https://github.com/Deltares/xugrid/blob/63a58022401c10f087bf780c0d4502534779625c/xugrid/ugrid/snapping.py#L41

Thinking it would come in handy.

It has a pretty serious flaw in that it "communicates" nearness. If the snapping distance is 1.1, with points a, b, c at 0, 1, 2; it will contract all of them into a single centroid at 1. Instead, it should contract points (a, b) together and leave c alone, or leave a alone and contract (b, c).

Once that's done, it can be exposed in the public API as well.