Skip to main content

Module broadphase

Module broadphase 

Source
Expand description

Broadphase acceleration for crowd models.

Every force-based or velocity-based model in this crate is fundamentally a pair-wise interaction: pedestrian i only needs to consider pedestrians j within a small cutoff radius where the interaction term is non-negligible. The naïve double loop is O(n^2); wrapping rustsim-broadphase::UniformGrid2 around it turns every step into O(n + n * k) where k is the average per-agent neighbour count, which is typically 5–20 for realistic crowd densities.

Each model picks its own cutoff through the function below:

  • NeighborGrid::rebuild drops the previous frame and re-inserts every pedestrian by its current position. Callers own the grid, so one allocation per simulation, not per tick.
  • NeighborGrid::for_each_neighbor hands the caller (j, pos_j, ped_j) for every pedestrian inside the cutoff radius of a source position, skipping the source index itself.

The grid keys are u64 agent indices cast from usize. Pedestrian slices must fit in u64::MAX — trivially satisfied in practice.

Structs§

NeighborGrid
Per-tick neighbour grid for the crowd models.
Scratch
Reusable scratch buffers for the crowd models.

Functions§

recommended_cell_size
Suggested cell size for a given interaction cutoff radius.