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

Function snap_graph

generative/snap.rs:197–226  ·  view source on GitHub ↗
(graph: GeometryGraph<D>, strategy: SnappingStrategy)

Source from the content-addressed store, hash-verified

195}
196
197pub fn snap_graph<D>(graph: GeometryGraph<D>, strategy: SnappingStrategy) -> GeometryGraph<D>
198where
199 D: EdgeType,
200{
201 // You can't look up a node in a graph by its weight (the coordinate)
202 // So we need an auxiliary GraphKdTree index for us to look up NodeIndices from their
203 // coordinates.
204 let mut index = GraphKdTree::new(2);
205 for node_idx in graph.node_indices() {
206 let node = graph[node_idx];
207 let coords = [node.0.x, node.0.y];
208
209 // Don't add duplicate vertices to the index
210 let closest = index.nearest(&coords, 1, &squared_euclidean).unwrap();
211 if let Some(closest) = closest.first() {
212 let (distance, _) = closest;
213 if *distance == 0.0 {
214 continue;
215 }
216 }
217 index.add(coords, node_idx).unwrap();
218 }
219
220 match strategy {
221 SnappingStrategy::ClosestPoint(tolerance) => {
222 snap_graph_closest_point(graph, &mut index, tolerance)
223 }
224 SnappingStrategy::RegularGrid(tolerance) => snap_graph_grid(graph, tolerance),
225 }
226}
227
228fn snap_graph_closest_point<D>(
229 mut graph: GeometryGraph<D>,

Callers 6

mainFunction · 0.85
mainFunction · 0.85
test_snap_graph_gridFunction · 0.85

Calls 2

snap_graph_closest_pointFunction · 0.85
snap_graph_gridFunction · 0.85