MCPcopy Create free account
hub / github.com/Notgnoshi/generative / snap_coord

Function snap_coord

generative/snap.rs:83–103  ·  view source on GitHub ↗
(to_snap: Coord, index: &mut GeomKdTree, tolerance: f64)

Source from the content-addressed store, hash-verified

81}
82
83fn snap_coord(to_snap: Coord, index: &mut GeomKdTree, tolerance: f64) -> Coord {
84 let query = [to_snap.x, to_snap.y];
85 let neighbors = index.within(&query, tolerance, &squared_euclidean).unwrap();
86
87 if !neighbors.is_empty() {
88 let (mut _distance, mut found_coords) = neighbors[0];
89 // If we found ourselves, snap to the next closest point
90 if found_coords == &to_snap && neighbors.len() > 1 {
91 // The next closest point
92 (_distance, found_coords) = neighbors[1];
93 }
94
95 // Remove the point that we snapped to, so that future snaps don't find it again
96 let snapped_coord = *found_coords;
97 index.remove(&query, &to_snap).unwrap();
98
99 snapped_coord
100 } else {
101 to_snap
102 }
103}
104
105fn snap_coord_grid(coord: Coord, tolerance: f64) -> Coord {
106 Coord {

Callers 1

snap_geom_implFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected