qualia_core_db/domains/geospatial/
canvas_query.rs1use super::spatial::{SpatialElement, SpatiotemporalQuadTree};
4
5pub fn query_region(
8 tree: &SpatiotemporalQuadTree,
9 bbox: (f64, f64, f64, f64),
10 time_range: (u64, u64),
11) -> Vec<u64> {
12 let (x1, y1, x2, y2) = bbox;
13 let (t0, t1) = time_range;
14 tree.query_region(x1, y1, x2, y2, t0, t1)
15}
16
17pub fn index_asset(
19 tree: &mut SpatiotemporalQuadTree,
20 h3_index: u64,
21 bounds: (f64, f64, f64, f64),
22 valid_from: u64,
23 valid_until: u64,
24) {
25 tree.insert(SpatialElement {
26 h3_index,
27 bounds,
28 t0: valid_from,
29 t1: valid_until,
30 });
31}
32
33#[cfg(test)]
34mod tests {
35 use super::*;
36
37 #[test]
38 fn query_region_delegates_to_quadtree() {
39 let mut tree = SpatiotemporalQuadTree::new((0.0, 0.0, 100.0, 100.0));
40 index_asset(&mut tree, 42, (10.0, 10.0, 20.0, 20.0), 100, 200);
41 let hits = query_region(&tree, (15.0, 15.0, 25.0, 25.0), (150, 160));
42 assert_eq!(hits, vec![42]);
43 }
44}