Struct BvhNodeWide

Source
#[repr(C, align(64))]
pub struct BvhNodeWide { /* private fields */ }
Expand description

A pair of tree nodes forming a 2-wide BVH node.

The BVH uses a memory layout where nodes are stored in pairs (left and right children) to improve cache coherency and enable SIMD optimizations. This structure represents a single entry in the BVH’s node array.

§Node Validity

Both left and right are guaranteed to be valid except for one special case:

  • Single leaf tree: Only left is valid, right is zeroed
  • All other cases: Both left and right are valid (tree has at least 2 leaves)

§Memory Layout

In 3D with f32 precision and SIMD enabled, this structure is:

  • Size: 64 bytes (cache line aligned)
  • Alignment: 64 bytes (matches typical CPU cache lines)
  • This alignment improves performance by reducing cache misses

§Example

use parry3d::partitioning::{Bvh, BvhBuildStrategy};
use parry3d::bounding_volume::Aabb;
use nalgebra::Point3;

let aabbs = vec![
    Aabb::new(Point3::origin(), Point3::new(1.0, 1.0, 1.0)),
    Aabb::new(Point3::new(2.0, 0.0, 0.0), Point3::new(3.0, 1.0, 1.0)),
    Aabb::new(Point3::new(4.0, 0.0, 0.0), Point3::new(5.0, 1.0, 1.0)),
];

let bvh = Bvh::from_leaves(BvhBuildStrategy::default(), &aabbs);

// Access the root node's children
// The BVH stores nodes as BvhNodeWide pairs internally
assert_eq!(bvh.leaf_count(), 3);

§See Also

  • BvhNode - Individual node in the pair
  • Bvh - The main BVH structure

Implementations§

Source§

impl BvhNodeWide

Source

pub fn zeros() -> Self

Creates a new BvhNodeWide with both children zeroed out.

This is primarily used internally during BVH construction and should rarely be needed in user code.

§Example
use parry3d::partitioning::BvhNodeWide;

let node_wide = BvhNodeWide::zeros();
assert_eq!(node_wide.leaf_count(), 0);
Source

pub fn as_array(&self) -> [&BvhNode; 2]

Returns the two nodes as an array of references.

This is useful for accessing the left or right node by index (0 or 1 respectively) instead of by name. Index 0 is the left node, index 1 is the right node.

§Example
use parry3d::partitioning::{Bvh, BvhBuildStrategy};
use parry3d::bounding_volume::{Aabb, BoundingVolume};
use nalgebra::Point3;

let aabbs = vec![
    Aabb::new(Point3::origin(), Point3::new(1.0, 1.0, 1.0)),
    Aabb::new(Point3::new(2.0, 0.0, 0.0), Point3::new(3.0, 1.0, 1.0)),
];

let bvh = Bvh::from_leaves(BvhBuildStrategy::default(), &aabbs);
// The root AABB should contain both leaves
assert!(bvh.root_aabb().contains(&aabbs[0]));
assert!(bvh.root_aabb().contains(&aabbs[1]));
§See Also
Source

pub fn as_array_mut(&mut self) -> [&mut BvhNode; 2]

Returns the two nodes as an array of mutable references.

This is useful for modifying the left or right node by index (0 or 1 respectively) instead of by name. Index 0 is the left node, index 1 is the right node.

§Example
use parry3d::partitioning::BvhNodeWide;
use nalgebra::Vector3;

let mut node_wide = BvhNodeWide::zeros();
let nodes = node_wide.as_array_mut();

// Scale both nodes by 2.0
let scale = Vector3::new(2.0, 2.0, 2.0);
nodes[0].scale(&scale);
nodes[1].scale(&scale);
§See Also
Source

pub fn merged(&self, my_id: u32) -> BvhNode

Merges both child nodes to create their parent node.

The parent’s AABB will be the union of both children’s AABBs, and the parent’s leaf count will be the sum of both children’s leaf counts. The my_id parameter becomes the parent’s children field, pointing back to this BvhNodeWide.

§Arguments
  • my_id - The index of this BvhNodeWide in the BVH’s node array
§Returns

A new BvhNode representing the parent of both children.

Source

pub fn leaf_count(&self) -> u32

Returns the total number of leaves contained in both child nodes.

This is the sum of the leaf counts of the left and right children. For leaf nodes, the count is 1. For internal nodes, it’s the sum of their descendants.

§Returns

The total number of leaves in the subtrees rooted at both children.

Trait Implementations§

Source§

impl Clone for BvhNodeWide

Source§

fn clone(&self) -> BvhNodeWide

Returns a duplicate 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 Debug for BvhNodeWide

Source§

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

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

impl Copy for BvhNodeWide

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.