#[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
leftis valid,rightis zeroed - All other cases: Both
leftandrightare 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
Implementations§
Source§impl BvhNodeWide
impl BvhNodeWide
Sourcepub fn zeros() -> Self
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);Sourcepub fn as_array(&self) -> [&BvhNode; 2]
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
as_array_mut- Mutable version
Sourcepub fn as_array_mut(&mut self) -> [&mut BvhNode; 2]
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
as_array- Immutable version
Sourcepub fn merged(&self, my_id: u32) -> BvhNode
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 thisBvhNodeWidein the BVH’s node array
§Returns
A new BvhNode representing the parent of both children.
Sourcepub fn leaf_count(&self) -> u32
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
impl Clone for BvhNodeWide
Source§fn clone(&self) -> BvhNodeWide
fn clone(&self) -> BvhNodeWide
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BvhNodeWide
impl Debug for BvhNodeWide
impl Copy for BvhNodeWide
Auto Trait Implementations§
impl Freeze for BvhNodeWide
impl RefUnwindSafe for BvhNodeWide
impl Send for BvhNodeWide
impl Sync for BvhNodeWide
impl Unpin for BvhNodeWide
impl UnwindSafe for BvhNodeWide
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.