use bevy::prelude::*;
use crate::{TComp, point::SpatialPoint};
#[allow(clippy::module_name_repetitions)]
pub trait UpdateSpatialAccess: SpatialAccess {
fn update(
&mut self,
data: impl Iterator<Item = (Self::Point, bool)>,
removed: impl Iterator<Item = Entity>,
) {
for (p, changed) in data {
if changed {
self.remove_point(p);
self.add(p);
}
}
for e in removed {
self.remove_entity(e);
}
}
fn add(&mut self, point: Self::Point);
fn remove_point(&mut self, point: Self::Point) -> bool;
fn remove_entity(&mut self, entity: Entity) -> bool;
fn clear(&mut self);
}
pub trait SpatialAccess: Send + Sync + 'static {
type Point: SpatialPoint;
type Comp: TComp;
type ResultT;
fn nearest_neighbour(&self, loc: <Self::Point as SpatialPoint>::Vec) -> Option<Self::ResultT>;
fn k_nearest_neighbour(
&self,
loc: <Self::Point as SpatialPoint>::Vec,
k: usize,
) -> Vec<Self::ResultT>;
fn within_distance(
&self,
loc: <Self::Point as SpatialPoint>::Vec,
distance: <Self::Point as SpatialPoint>::Scalar,
) -> Vec<Self::ResultT>;
}