pub mod functions;
pub mod geometry;
pub mod rtree;
pub use functions::*;
pub use geometry::{BoundingBox, Geometry, LineString, Point, Polygon};
pub use rtree::SpatialIndex;
use crate::dictionary::NodeId;
use crate::error::{Result, TdbError};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SpatialQuery {
WithinDistance {
center: Point,
distance: f64,
},
IntersectsBBox {
bbox: BoundingBox,
},
Contains {
point: Point,
},
KNearestNeighbors {
point: Point,
k: usize,
},
}
#[derive(Debug, Clone)]
pub struct SpatialQueryResult {
pub node_id: NodeId,
pub geometry: Geometry,
pub distance: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SpatialStats {
pub geometry_count: usize,
pub points_count: usize,
pub polygons_count: usize,
pub linestrings_count: usize,
pub rtree_depth: usize,
pub rtree_node_count: usize,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_spatial_module_exports() {
let _point = Point::new(0.0, 0.0);
let _bbox = BoundingBox::new(0.0, 0.0, 1.0, 1.0);
let _index = SpatialIndex::new();
}
#[test]
fn test_spatial_query_types() {
let query = SpatialQuery::WithinDistance {
center: Point::new(40.7128, -74.0060),
distance: 1000.0,
};
assert!(matches!(query, SpatialQuery::WithinDistance { .. }));
let query2 = SpatialQuery::IntersectsBBox {
bbox: BoundingBox::new(0.0, 0.0, 1.0, 1.0),
};
assert!(matches!(query2, SpatialQuery::IntersectsBBox { .. }));
}
#[test]
fn test_spatial_stats_creation() {
let stats = SpatialStats {
geometry_count: 100,
points_count: 60,
polygons_count: 30,
linestrings_count: 10,
rtree_depth: 4,
rtree_node_count: 25,
};
assert_eq!(stats.geometry_count, 100);
assert_eq!(stats.rtree_depth, 4);
}
}