Using this crate, the user can create three flavors of the same fundamental data structure. The different characteristics are exlored more in depth in the broccoli book
collections modules lists the tree types and they are all described there, but the
TL;DR is use
Tree and fill it with
BBox<N,&mut T> unless you want
to use functions like
In which case use
Checkout the github examples.
Parallel versions of construction and colliding pair finding functions
are provided. They use
rayon under the hood which uses work stealing to
parallelize divide and conquer style recursive functions.
Num trait used for the aabbs inserted into the tree must implement
thus you can't add
f64. However, you can use the
ordered_float crate, which
is re-exported at [
The broccoli book mentioned above compares performance. For best performance,
you will likely want to convert the floats to integers anyway.
A lot is done to forbid the user from violating the invariants of the tree once constructed
while still allowing them to mutate parts of each element of the tree. The user can mutably traverse
the tree but the mutable references returns are hidden behind the
PMut<T> type that forbids
mutating the aabbs.
Raw pointers are used for the container types in the container module and for caching the results of finding colliding pairs.
query::Queries::multi_rect uses unsafety to allow the user to have mutable references to elements
that belong to rectangle regions that don't intersect at the same time. This is why
Aabb trait is unsafe.
If you shorten "broadphase collision" to "broad colli" and say it fast, it sounds like broccoli. Broccoli also have tree like properties and broccoli uses a tree data structure.
Contains code to help analyze the
Container trees that deref to
Helper functions to convert aabbs in floats to integers
Contains node-level building block structs and visitors used for a
Contains code to write generic code that can be run in parallel, or sequentially. The api is exposed in case users find it useful when writing parallel query code to operate on the tree.
Provides a mutable pointer type that is more restrictive that
The broccoli prelude.
Module contains query related structs.
A version of Tree where the elements are not sorted along each axis, like a KD Tree.
For comparison, a normal kd-tree is provided by
A 1D range. Internally represented as start and end. (as opposed to a start and length) This means that subdivision does not result in any floating point calculations. The start value must be <= the end value. There is no protection against "degenerate" Ranges where start>end. Behavior of any of the functions with degenrate Ranges is unspecified.
An axis aligned rectangle. Stored as two Ranges. It is a semi-closed rectangle. A point is considered inside the rectangle if it is in [start,end) for both x and y.
The data structure this crate revoles around.
Trait to signify that this object has an axis aligned bounding box.
Trait exposes an api where you can return a read-only reference to the axis-aligned bounding box and at the same time return a mutable reference to a seperate inner section.
The underlying number type used for the tree. It is auto implemented by all types that satisfy the type constraints. Notice that no arithmatic is possible. The tree is constructed using only comparisons and copying.
Shorthand constructor of
Returns the default axis type.
Convenience function to create a Rect.
The default starting axis of a