MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / overlapping_squares

Function overlapping_squares

nodedb-spatial/src/predicates/intersection.rs:238–258  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

236
237 #[test]
238 fn overlapping_squares() {
239 let a = square(0.0, 10.0);
240 let b = square(5.0, 15.0);
241 let result = st_intersection(&a, &b);
242 if let Geometry::Polygon { coordinates } = &result {
243 assert!(!coordinates[0].is_empty());
244 // Intersection should be approximately [5,5] to [10,10].
245 let xs: Vec<f64> = coordinates[0].iter().map(|c| c[0]).collect();
246 let ys: Vec<f64> = coordinates[0].iter().map(|c| c[1]).collect();
247 let min_x = xs.iter().cloned().fold(f64::INFINITY, f64::min);
248 let max_x = xs.iter().cloned().fold(f64::NEG_INFINITY, f64::max);
249 let min_y = ys.iter().cloned().fold(f64::INFINITY, f64::min);
250 let max_y = ys.iter().cloned().fold(f64::NEG_INFINITY, f64::max);
251 assert!((min_x - 5.0).abs() < 0.01, "min_x={min_x}");
252 assert!((max_x - 10.0).abs() < 0.01, "max_x={max_x}");
253 assert!((min_y - 5.0).abs() < 0.01, "min_y={min_y}");
254 assert!((max_y - 10.0).abs() < 0.01, "max_y={max_y}");
255 } else {
256 panic!("expected Polygon, got {:?}", result.geometry_type());
257 }
258 }
259
260 #[test]
261 fn contained_square() {

Callers

nothing calls this directly

Calls 5

st_intersectionFunction · 0.85
collectMethod · 0.80
foldMethod · 0.80
squareFunction · 0.70
iterMethod · 0.45

Tested by

no test coverage detected