Skip to main content

DynamicTree

Struct DynamicTree 

Source
pub struct DynamicTree { /* private fields */ }
Expand description

The dynamic tree structure. (b2DynamicTree)

A dynamic AABB tree broad-phase. Leaf nodes are proxies with an AABB, used to hold a user collision object. Nodes are pooled and relocatable, so node indices are used rather than pointers.

Implementations§

Source§

impl DynamicTree

Source

pub fn create_proxy( &mut self, aabb: Aabb, category_bits: u64, user_data: u64, ) -> i32

Create a proxy in the tree as a leaf node. Returns the node index. (b2DynamicTree_CreateProxy)

Source

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

Destroy a proxy. This asserts if the id is invalid. (b2DynamicTree_DestroyProxy)

Source

pub fn move_proxy(&mut self, proxy_id: i32, aabb: Aabb)

Move a proxy to a new AABB by removing and reinserting into the tree. (b2DynamicTree_MoveProxy)

Source

pub fn enlarge_proxy(&mut self, proxy_id: i32, aabb: Aabb)

Enlarge a proxy and enlarge ancestors as necessary. (b2DynamicTree_EnlargeProxy)

Source

pub fn set_category_bits(&mut self, proxy_id: i32, category_bits: u64)

Modify the category bits on a proxy. This is an expensive operation. (b2DynamicTree_SetCategoryBits)

Source§

impl DynamicTree

Source

pub fn query( &self, aabb: Aabb, mask_bits: u64, callback: impl FnMut(i32, u64) -> bool, ) -> TreeStats

Query an AABB for overlapping proxies. The callback is called for each proxy that overlaps the supplied AABB and passes the mask-bits filter; return false from the callback to stop. (b2DynamicTree_Query)

Source

pub fn query_all( &self, aabb: Aabb, callback: impl FnMut(i32, u64) -> bool, ) -> TreeStats

Query an AABB for overlapping proxies with no filtering. (b2DynamicTree_QueryAll)

Source

pub fn ray_cast( &self, input: &RayCastInput, mask_bits: u64, callback: impl FnMut(&RayCastInput, i32, u64) -> f32, ) -> TreeStats

Ray cast against the proxies in the tree. The callback performs an exact ray cast when the proxy contains a shape, and returns the new ray fraction:

  • return 0 to terminate the ray cast
  • return a value less than the input max_fraction to clip the ray
  • return the input max_fraction to continue without clipping

(b2DynamicTree_RayCast)

Source

pub fn box_cast( &self, input: &BoxCastInput, mask_bits: u64, callback: impl FnMut(&BoxCastInput, i32, u64) -> f32, ) -> TreeStats

Cast a swept AABB through the tree. The callback returns the new cast fraction, with the same semantics as DynamicTree::ray_cast. (b2DynamicTree_BoxCast)

Source§

impl DynamicTree

Source

pub fn rebuild(&mut self, full_build: bool) -> i32

Rebuild the tree while retaining subtrees that haven’t changed. Returns the number of boxes sorted. (b2DynamicTree_Rebuild)

Source§

impl DynamicTree

Source

pub fn validate(&self)

Validate this tree. For testing. (b2DynamicTree_Validate)

Source

pub fn validate_no_enlarged(&self)

Validate this tree has no enlarged AABBs. For testing. (b2DynamicTree_ValidateNoEnlarged)

Source§

impl DynamicTree

Source

pub fn new(proxy_capacity: i32) -> DynamicTree

Constructing the tree initializes the node pool. (b2DynamicTree_Create)

Source

pub fn destroy(&mut self)

Destroy the tree, freeing the node pool. (b2DynamicTree_Destroy)

Rust would drop the storage automatically; this mirrors the C function (which leaves a zeroed struct) so ported call sites and tests read the same.

Source

pub fn node_count(&self) -> i32

The number of allocated nodes.

Source

pub fn proxy_count(&self) -> i32

Get the number of proxies created. (b2DynamicTree_GetProxyCount)

Source

pub fn category_bits(&self, proxy_id: i32) -> u64

Get the category bits on a proxy. (b2DynamicTree_GetCategoryBits)

Source

pub fn height(&self) -> i32

Get the height of the binary tree. (b2DynamicTree_GetHeight)

Source

pub fn area_ratio(&self) -> f32

Get the ratio of the sum of the node areas to the root area. (b2DynamicTree_GetAreaRatio)

Source

pub fn root_bounds(&self) -> Aabb

Get the bounding box that contains the entire tree. (b2DynamicTree_GetRootBounds)

Source

pub fn byte_count(&self) -> i32

Get the number of bytes used by this tree. (b2DynamicTree_GetByteCount)

Source

pub fn user_data(&self, proxy_id: i32) -> u64

Get proxy user data. (b2DynamicTree_GetUserData)

Source

pub fn aabb(&self, proxy_id: i32) -> Aabb

Get the AABB of a proxy. (b2DynamicTree_GetAABB)

Trait Implementations§

Source§

impl Clone for DynamicTree

Source§

fn clone(&self) -> DynamicTree

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DynamicTree

Source§

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

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

impl Default for DynamicTree

Source§

fn default() -> DynamicTree

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

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.