euv_engine/spatial/struct.rs
1use crate::*;
2
3/// A uniform-grid spatial hash for broad-phase collision culling in 2D.
4///
5/// Bodies are inserted by their world-space axis-aligned bounding box.
6/// A query returns all candidate indices whose AABBs overlap the query region,
7/// dramatically reducing narrow-phase collision checks from O(n²) to near O(n).
8#[derive(Clone, Data, New, PartialEq)]
9pub struct SpatialHashGrid2D {
10 /// The world-space size of each grid cell.
11 #[get(type(copy))]
12 pub(crate) cell_size: f64,
13 /// The inverse of `cell_size`, precomputed for fast coordinate-to-cell hashing.
14 #[get(type(copy))]
15 #[set(pub(crate))]
16 #[new(skip)]
17 pub(crate) inverse_cell_size: f64,
18 /// The hash map from cell key to the list of body indices occupying that cell.
19 #[get_mut(pub(crate))]
20 #[new(skip)]
21 pub(crate) cells: SpatialCellMap2D,
22}
23
24/// A uniform-grid spatial hash for broad-phase collision culling in 3D.
25///
26/// Bodies are inserted by their world-space axis-aligned bounding box.
27/// A query returns all candidate indices whose AABBs overlap the query region,
28/// dramatically reducing narrow-phase collision checks from O(n²) to near O(n).
29#[derive(Clone, Data, New, PartialEq)]
30pub struct SpatialHashGrid3D {
31 /// The world-space size of each grid cell.
32 #[get(type(copy))]
33 pub(crate) cell_size: f64,
34 /// The inverse of `cell_size`, precomputed for fast coordinate-to-cell hashing.
35 #[get(type(copy))]
36 #[set(pub(crate))]
37 #[new(skip)]
38 pub(crate) inverse_cell_size: f64,
39 /// The hash map from cell key to the list of body indices occupying that cell.
40 #[get_mut(pub(crate))]
41 #[new(skip)]
42 pub(crate) cells: SpatialCellMap3D,
43}