use crate::order::{OrderClause, OrderTarget};
use crate::{NullOrder, SortDirection};
#[derive(Debug, Clone, PartialEq)]
pub enum SpatialFilter {
CoversGeographyPoint {
column: &'static str,
lng: f64,
lat: f64,
},
DWithinGeographyPoint {
column: &'static str,
lng: f64,
lat: f64,
radius_meters: f64,
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SpatialPoint {
pub lng: f64,
pub lat: f64,
}
pub const fn point(lng: f64, lat: f64) -> SpatialPoint {
SpatialPoint { lng, lat }
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SpatialDistanceExpr {
column: &'static str,
point: SpatialPoint,
}
impl SpatialDistanceExpr {
pub(super) const fn new(column: &'static str, point: SpatialPoint) -> Self {
Self { column, point }
}
pub fn asc(self) -> OrderClause {
self.order(SortDirection::Asc)
}
pub fn desc(self) -> OrderClause {
self.order(SortDirection::Desc)
}
fn order(self, direction: SortDirection) -> OrderClause {
OrderClause {
target: OrderTarget::SpatialDistance {
column: self.column,
lng: self.point.lng,
lat: self.point.lat,
},
direction,
null_order: NullOrder::Last,
}
}
}