Loading repository data…
Loading repository data…
johanhelsing / repository
An opinionated 2D sparse grid made for use with Bevy. For storing and querying entities
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
An opinionated 2D sparse grid made for use with Bevy. For storing and querying entities.
Personally, I'm using it for simple stupid collision broad phase in a couple of my projects.
use bevy::{
math::{bounding::Aabb2d, vec2},
prelude::*,
platform::collections::HashSet
};
use bevy_sparse_grid_2d::SparseGrid2d;
const TILE_SIZE: usize = 1; // how wide each cell is
let mut db = SparseGrid2d::<TILE_SIZE>::default();
let e1 = Entity::from_raw_u32(1).unwrap();
let e2 = Entity::from_raw_u32(2).unwrap();
db.insert_point(vec2(0.5, 0.5), e1);
db.insert_point(vec2(0.499, 0.501), e2);
// query a single point
let matches: HashSet<_> = db.point_iter(vec2(0.499, 0.501)).collect();
assert!(matches.contains(&e1));
assert!(matches.contains(&e2));
assert_eq!(matches.len(), 2);
// query an aabb
let aabb = Aabb2d::new(Vec2::new(0.001, 0.001), Vec2::new(0.001, 0.001));
let matches = db.query_aabb(aabb);
assert!(matches.contains(&e1));
assert!(matches.contains(&e2));
assert_eq!(matches.len(), 2);
See tests in lib.rs
The main branch targets the latest bevy release.
| bevy | bevy_sparse_grid_2d |
|---|---|
| 0.19 | 0.10, main |
| 0.18 | 0.9 |
| 0.17 | 0.8 |
| 0.16 | 0.7 |
| 0.15 | 0.6 |
| 0.14 | 0.5 |
| 0.13 | 0.4 |
| 0.12 | 0.3 |
| 0.11 | 0.2 |
| 0.10 | 0.1 |
MIT or Apache-2.0
PRs welcome!