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

Function test_graph

generative/triangulation.rs:241–317  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

239
240 #[test]
241 fn test_graph() {
242 let wkt = b"POINT (65.85186826230156 -39.36525618186133)\n\
243 POINT (61.35756898870892 -34.85194590696902)\n\
244 POINT (38.25507241174806 -24.06029365638358)\n\
245 POINT (9.25896849065506 -63.356505724778266)\n\
246 POINT (-5.692741678486288 -17.181741298068346)\n\
247 POINT (-32.93567551272198 -61.274655097506745)\n";
248 let geometries: Vec<_> = read_wkt_geometries(&wkt[..]).collect();
249 assert_eq!(geometries.len(), 6);
250 let points = flatten_geometries_into_points_ref(geometries.iter());
251 let triangulation = triangulate(points).unwrap();
252
253 // NOTE: This all makes much more sense if you draw a picture! Pipe the following through
254 // render.py:
255 // cargo test --all-features test_graph -- --nocapture | ./tools/render.py
256 #[cfg(feature = "test-io")]
257 {
258 let lines = triangulation.lines().map(geo::Geometry::Line);
259 crate::io::write_wkt_geometries(std::io::stdout(), geometries).unwrap();
260 crate::io::write_wkt_geometries(std::io::stdout(), lines).unwrap();
261 }
262
263 let triangles = [3, 5, 4, 4, 2, 3, 2, 1, 3, 1, 0, 3];
264 assert_eq!(triangulation.triangulation.triangles, triangles);
265 let halfedges = [EMPTY, EMPTY, 5, EMPTY, 8, 2, EMPTY, 11, 4, EMPTY, EMPTY, 7];
266 assert_eq!(triangulation.triangulation.halfedges, halfedges);
267
268 // NOTE: None of the indices from 'triangles' or 'halfedges' index into 'hull'! You have to
269 // create the hull half-edges by looping over the hull. However, be aware that the hull is
270 // an open LINESTRING, and needs to be implicitly closed in order to capture the last edge!
271
272 let hull = [1, 0, 3, 5, 4, 2];
273 assert_eq!(triangulation.triangulation.hull, hull);
274
275 let graph = triangulation.digraph();
276 // It's not necessary that the edges be compared in order, but that's easiest to implement
277 // here.
278 let edges: Vec<_> = graph
279 .raw_edges()
280 .iter()
281 .map(|e| (e.source().index(), e.target().index()))
282 .collect();
283 let expected = vec![
284 (1, 0),
285 (0, 3),
286 (3, 5),
287 (5, 4),
288 (4, 2),
289 (2, 1),
290 (3, 4),
291 (3, 2),
292 (4, 3),
293 (3, 1),
294 (2, 3),
295 (1, 3),
296 ];
297 assert_eq!(edges, expected);
298

Callers

nothing calls this directly

Calls 7

read_wkt_geometriesFunction · 0.85
triangulateFunction · 0.85
write_wkt_geometriesFunction · 0.85
linesMethod · 0.80
digraphMethod · 0.80
graphMethod · 0.80

Tested by

no test coverage detected