pub struct B2dynamicTree<UserDataType> { /* private fields */ }
Expand description

A dynamic AABB tree broad-phase, inspired by Nathanael Presson’s btDbvt. A dynamic tree arranges data in a binary tree to accelerate queries such as volume queries and ray casts. Leafs are proxies with an AABB. In the tree we expand the proxy AABB by b2_fatAABBFactor so that the proxy AABB is bigger than the client object. This allows the client object to move by small amounts without triggering a tree update.

Nodes are pooled and relocatable, so we use node indices rather than pointers.

Implementations§

source§

impl<UserDataType: Clone + Default> B2dynamicTree<UserDataType>

source

pub fn new() -> Self

Constructing the tree initializes the node pool.

source

pub fn create_proxy(&mut self, aabb: B2AABB, user_data: &UserDataType) -> i32

destroy the tree, freeing the node pool. create a proxy. Provide a tight fitting AABB and a user_data pointer.

source

pub fn destroy_proxy(&mut self, proxy_id: i32)

destroy a proxy. This asserts if the id is invalid.

source

pub fn move_proxy( &mut self, proxy_id: i32, aabb1: B2AABB, displacement: B2vec2 ) -> bool

Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB, then the proxy is removed from the tree and re-inserted. Otherwise the function returns immediately.

@return true if the proxy was re-inserted.

source

pub fn get_user_data(&self, proxy_id: i32) -> Option<UserDataType>

Get proxy user data.

@return the proxy user data or 0 if the id is invalid.

source

pub fn was_moved(&self, proxy_id: i32) -> bool

source

pub fn clear_moved(&mut self, proxy_id: i32)

source

pub fn get_fat_aabb(&self, proxy_id: i32) -> B2AABB

Get the fat AABB for a proxy.

source

pub fn query<F: QueryCallback>(&self, callback: F, aabb: B2AABB)

query an AABB for overlapping proxies. The callback class is called for each proxy that overlaps the supplied AABB.

source

pub fn ray_cast<T: RayCastCallback>(&self, callback: T, input: &B2rayCastInput)

Ray-cast against the proxies in the tree. This relies on the callback to perform a exact ray-cast in the case were the proxy contains a shape. The callback also performs the any collision filtering. This has performance roughly equal to k * log(n), where k is the number of collisions and n is the number of proxies in the tree.

  • input - the ray-cast input data. The ray extends from p1 to p1 + max_fraction * (p2 - p1).
  • callback - a callback class that is called for each proxy that is hit by the ray.
source

pub fn validate(&self)

Validate this tree. For testing.

source

pub fn get_height(&self) -> i32

Compute the height of the binary tree in O(n) time. Should not be called often.

source

pub fn get_max_balance(&self) -> i32

Get the maximum balance of an node in the tree. The balance is the difference in height of the two children of a node.

source

pub fn get_area_ration(&self) -> f32

Get the ratio of the sum of the node areas to the root area.

source

pub fn rebuild_bottom_up(&mut self)

Build an optimal tree. Very expensive. For testing.

source

pub fn shift_origin(&mut self, new_origin: B2vec2)

Shift the world origin. Useful for large worlds. The shift formula is: position -= new_origin

  • new_origin - the new origin with respect to the old origin

Trait Implementations§

source§

impl<UserDataType: Clone> Clone for B2dynamicTree<UserDataType>

source§

fn clone(&self) -> B2dynamicTree<UserDataType>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<UserDataType: Debug> Debug for B2dynamicTree<UserDataType>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<UserDataType: Default> Default for B2dynamicTree<UserDataType>

source§

fn default() -> B2dynamicTree<UserDataType>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<UserDataType> RefUnwindSafe for B2dynamicTree<UserDataType>where UserDataType: RefUnwindSafe,

§

impl<UserDataType> Send for B2dynamicTree<UserDataType>where UserDataType: Send,

§

impl<UserDataType> Sync for B2dynamicTree<UserDataType>where UserDataType: Sync,

§

impl<UserDataType> Unpin for B2dynamicTree<UserDataType>where UserDataType: Unpin,

§

impl<UserDataType> UnwindSafe for B2dynamicTree<UserDataType>where UserDataType: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.