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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! A bounding-volume hierarchy for in-game broad-phase collision detection
//!
//! The core type is [`Bvh`]. It supports insertion and removal as well as iterating over all overlaping pairs.
//!
//! The [`Bvh`] type is generic over the type of bounding volume,
//! so you may choose one in [`volumes`] or implement yourself the [`BoundingVolume`] trait.
//!
//! # Usage example
//!
//! ```
//! use bvh_arena::{Bvh, volumes::Aabb};
//!
//! // The built-in `Aabb` type can be created from anything that implement `Into<[f32; D]>`
//! // So we can use glam's vector types. But you may use anything else you like.
//! use glam::Vec2;
//!
//! // Create a bounding volume hierarchy.
//! let mut bvh: Bvh<u8, Aabb<2>> = Bvh::default();
//!
//! // Insert bounding volumes
//! bvh.insert(1, Aabb::from_min_max(Vec2::ZERO, Vec2::new(1.0, 1.0)));
//! bvh.insert(2, Aabb::from_min_max(Vec2::new(0.5, 0.5), Vec2::new(2.0, 2.0)));
//! bvh.insert(3, Aabb::from_min_max(Vec2::new(3.0, 2.0), Vec2::new(4.0, 4.0)));
//!
//! // Insertion returns an Id that can be used to remove the bounding volume
//! let id = bvh.insert(4, Aabb::from_min_max(Vec2::new(3.0, 2.0), Vec2::new(4.0, 4.0)));
//! bvh.remove(id);
//!
//! let mut pairs: Vec<(u8, u8)> = Vec::new();
//!
//! // Iteration over overlaping pairs
//! bvh.for_each_overlaping_pair(|data1, data2| pairs.push((*data1, *data2)));
//!
//! assert_eq!(pairs, vec![(1, 2)]);
//! ```
pub use ;
/// A type that represent a bounding volume, useful for broad collision detection