1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
use hurrycurry_protocol::glam::Vec2;
use std::{collections::HashMap, hash::Hash};
// TODO stub implementation. please implement
pub struct SpatialIndex<T> {
entries: HashMap<T, Vec2>,
}
impl<T: Eq + Hash + Copy> SpatialIndex<T> {
pub fn update_entry(&mut self, id: T, position: Vec2) {
self.entries.insert(id, position);
}
pub fn remove_entry(&mut self, id: T) {
self.entries.remove(&id);
}
pub fn all(&self, mut cb: impl FnMut(T, Vec2)) {
for (&e, &pos) in &self.entries {
cb(e, pos)
}
}
pub fn query(&self, _position: Vec2, _radius: f32, cb: impl FnMut(T, Vec2)) {
self.all(cb)
}
}
impl<T> Default for SpatialIndex<T> {
fn default() -> Self {
Self {
entries: Default::default(),
}
}
}
|