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

Function join_overlapping_squares

nodedb-spatial/src/spatial_join.rs:118–176  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

116
117 #[test]
118 fn join_overlapping_squares() {
119 // Left side: 5 squares at positions (0,0), (5,5), (10,10), (15,15), (20,20).
120 let left: Vec<(u64, Geometry)> = (0..5)
121 .map(|i| {
122 let base = (i * 5) as f64;
123 (
124 i as u64,
125 Geometry::polygon(vec![vec![
126 [base, base],
127 [base + 4.0, base],
128 [base + 4.0, base + 4.0],
129 [base, base + 4.0],
130 [base, base],
131 ]]),
132 )
133 })
134 .collect();
135
136 // Right side: 5 squares offset by 2.
137 let right: Vec<(u64, Geometry)> = (0..5)
138 .map(|i| {
139 let base = (i * 5 + 2) as f64;
140 (
141 100 + i as u64,
142 Geometry::polygon(vec![vec![
143 [base, base],
144 [base + 4.0, base],
145 [base + 4.0, base + 4.0],
146 [base, base + 4.0],
147 [base, base],
148 ]]),
149 )
150 })
151 .collect();
152
153 // Build index on left side.
154 let index = build_join_index(&left);
155
156 // Probe with right side.
157 let probe_entries: Vec<(u64, BoundingBox)> = right
158 .iter()
159 .map(|(id, geom)| (*id, geometry_bbox(geom)))
160 .collect();
161
162 let left_map: std::collections::HashMap<u64, Geometry> = left.into_iter().collect();
163 let right_map: std::collections::HashMap<u64, Geometry> = right.into_iter().collect();
164
165 let result = spatial_join(
166 &index,
167 &probe_entries,
168 &|id| left_map.get(&id).cloned(),
169 &|id| right_map.get(&id).cloned(),
170 SpatialJoinPredicate::Intersects,
171 );
172
173 // Adjacent overlapping squares should produce matches.
174 assert!(!result.pairs.is_empty(), "expected some join matches");
175 assert!(result.probes == 5); // One probe per right entry.

Callers

nothing calls this directly

Calls 6

build_join_indexFunction · 0.85
geometry_bboxFunction · 0.85
spatial_joinFunction · 0.85
collectMethod · 0.80
iterMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected