#tree #kdtree #broadphase #space-partitioning #no_std

no-std broccoli

broadphase collision detection algorithms

6 releases

new 0.1.6 Oct 20, 2020
0.1.5 Oct 16, 2020

#591 in Data structures

27 downloads per month

MIT/Apache

2MB
4.5K SLoC

Overview

Broccoli is a broadphase collision detection library. The base data structure is a hybrid between a KD Tree and Sweep and Prune.

Inner projects

The broccoli_demo inner project is meant to show case the use of these algorithms. The report inner project generates benches used in the broccoli book.

Screenshot

Screen capture from the inner dinotree_alg_demo project.

screenshot

Example

use broccoli::prelude::*;

fn main() {
    let mut aabbs = [
        bbox(rect(0isize, 10, 0, 10), 0),
        bbox(rect(15, 20, 15, 20), 0),
        bbox(rect(5, 15, 5, 15), 0),
    ];

    //Create a layer of direction.
    let mut ref_aabbs = aabbs.iter_mut().collect::<Vec<_>>();

    //This will change the order of the elements in bboxes,
    //but this is okay since we populated it with mutable references.
    let mut tree = broccoli::new(&mut ref_aabbs);

    //Find all colliding aabbs.
    tree.find_colliding_pairs_mut(|a, b| {
        *a += 1;
        *b += 1;
    });

    assert_eq!(aabbs[0].inner, 1);
    assert_eq!(aabbs[1].inner, 0);
    assert_eq!(aabbs[2].inner, 1);
}

Dependencies