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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// mlodato, 20190318

//! # Overview
//! 
//! broadphase-rs is a broadphase collision detection library.  It transforms object bounds into a lightweight
//! spatial index representation.  These indices are integer values which are sorted directly to yield a
//! result which is a topologically-sorted Morton order, after which full-system collision detection can be
//! accomplished by a single pass over the sorted list with only a minimal auxiliary stack necessary to maintain
//! state.  Collision tests between indices are accomplished with simple bitwise shifts, masks, and XORs.
//! 
//! This method is capable of supporting objects of varying scale (unlike uniform grids), while having a
//! straightforward, non-hierarchical structure in memory (unlike quad- or oct-trees), as the entire
//! representation exists in a single vector of index/object pairs.
//! 
//! # Usage
//! 
//! [`Layer`]: struct.Layer.html
//! 
//! [`Layer`] is the "main" struct of broadphase — this is where the sorted list of
//! spatial indices is stored.
//! 
//! The usual sequence of operations on a [`Layer`] is as follows:
//! 
//! ```rust
//! extern crate zvxryb_broadphase as broadphase;
//! # extern crate cgmath;
//! 
//! use broadphase::{Bounds, Layer, LayerBuilder, Index64_3D};
//! type ID = u64;
//! 
//! # use cgmath::Point3;
//! # fn doc_main<Iter>(system_bounds: Bounds<Point3<f32>>, objects: Iter)
//! # where
//! #     Iter: Iterator<Item = (Bounds<Point3<f32>>, ID)>
//! # {
//! let mut layer: Layer<Index64_3D, ID> = LayerBuilder::new().build();
//! 
//! // clears existing object index-ID pairs:
//! layer.clear();
//! 
//! // appends an iterator of object bounds-ID pairs to the layer:
//! layer.extend(system_bounds, objects);
//! 
//! // scans the layer for collisions:
//! let potential_collisions = layer.scan();
//! # }
//! ```

extern crate cgmath;
extern crate num_traits;
extern crate rustc_hash;

#[cfg(any(test, feature="serde"))]
#[macro_use]
extern crate serde;

#[cfg(feature="parallel")]
extern crate rayon;

#[cfg(feature="parallel")]
extern crate thread_local;

#[cfg(test)]
extern crate rand;

#[cfg(test)]
extern crate rand_chacha;

#[macro_use]
extern crate log;

#[macro_use]
extern crate smallvec;

mod traits;
mod geom;
mod index;
mod layer;

pub use crate::geom::{Bounds, TestGeometry, RayTestGeometry, SystemBounds};
pub use crate::index::{SpatialIndex, Index32_2D, Index64_2D, Index64_3D};
pub use crate::layer::{Layer, LayerBuilder};