diff --git a/src/bounding_hierarchy.rs b/src/bounding_hierarchy.rs index f38ca8e..264d7c4 100644 --- a/src/bounding_hierarchy.rs +++ b/src/bounding_hierarchy.rs @@ -5,11 +5,10 @@ use nalgebra::{ }; use num::{Float, FromPrimitive, Signed}; -use crate::aabb::Bounded; +use crate::aabb::{AabbIntersection, Bounded}; #[cfg(feature = "rayon")] use crate::bvh::rayon_executor; use crate::bvh::BvhNodeBuildArgs; -use crate::ray::Ray; /// Encapsulates the required traits for the value type used in the Bvh. pub trait BHValue: @@ -240,9 +239,9 @@ pub trait BoundingHierarchy { /// [`BoundingHierarchy`]: trait.BoundingHierarchy.html /// [`Aabb`]: ../aabb/struct.Aabb.html /// - fn traverse<'a, Shape: BHShape>( + fn traverse<'a, Query: AabbIntersection, Shape: BHShape>( &'a self, - ray: &Ray, + query: &Query, shapes: &'a [Shape], ) -> Vec<&'a Shape>; @@ -258,12 +257,12 @@ impl> BoundingHierarchy>( + fn traverse<'a, Query: AabbIntersection, Shape: BHShape>( &'a self, - ray: &Ray, + query: &Query, shapes: &'a [Shape], ) -> Vec<&'a Shape> { - H::traverse(self, ray, shapes) + H::traverse(self, query, shapes) } fn build_with_executor< diff --git a/src/bvh/bvh_impl.rs b/src/bvh/bvh_impl.rs index 9c53cdd..da86adc 100644 --- a/src/bvh/bvh_impl.rs +++ b/src/bvh/bvh_impl.rs @@ -410,12 +410,12 @@ impl BoundingHierarchy for Bvh::build(shapes) } - fn traverse<'a, Shape: Bounded>( + fn traverse<'a, Query: AabbIntersection, Shape: Bounded>( &'a self, - ray: &Ray, + query: &Query, shapes: &'a [Shape], ) -> Vec<&'a Shape> { - self.traverse(ray, shapes) + self.traverse(query, shapes) } fn pretty_print(&self) { diff --git a/src/flat_bvh.rs b/src/flat_bvh.rs index 718383d..bd8126c 100644 --- a/src/flat_bvh.rs +++ b/src/flat_bvh.rs @@ -1,8 +1,7 @@ //! This module exports methods to flatten the [`Bvh`] into a [`FlatBvh`] and traverse it iteratively. -use crate::aabb::{Aabb, Bounded}; +use crate::aabb::{Aabb, AabbIntersection, Bounded}; use crate::bounding_hierarchy::{BHShape, BHValue, BoundingHierarchy}; use crate::bvh::{Bvh, BvhNode}; -use crate::ray::Ray; use num::Float; @@ -382,7 +381,11 @@ impl BoundingHierarchy for /// let flat_bvh = FlatBvh::build(&mut shapes); /// let hit_shapes = flat_bvh.traverse(&ray, &shapes); /// ``` - fn traverse<'a, B: Bounded>(&'a self, ray: &Ray, shapes: &'a [B]) -> Vec<&'a B> { + fn traverse<'a, Q: AabbIntersection, B: Bounded>( + &'a self, + query: &Q, + shapes: &'a [B], + ) -> Vec<&'a B> { let mut hit_shapes = Vec::new(); let mut index = 0; @@ -396,13 +399,13 @@ impl BoundingHierarchy for if node.entry_index == u32::MAX { // If the entry_index is MAX_UINT32, then it's a leaf node. let shape = &shapes[node.shape_index as usize]; - if ray.intersects_aabb(&shape.aabb()) { + if query.intersects_aabb(&shape.aabb()) { hit_shapes.push(shape); } // Exit the current node. index = node.exit_index as usize; - } else if ray.intersects_aabb(&node.aabb) { + } else if query.intersects_aabb(&node.aabb) { // If entry_index is not MAX_UINT32 and the Aabb test passes, then // proceed to the node in entry_index (which goes down the bvh branch). index = node.entry_index as usize; diff --git a/src/ray/ray_impl.rs b/src/ray/ray_impl.rs index ee2a8ea..30e887e 100644 --- a/src/ray/ray_impl.rs +++ b/src/ray/ray_impl.rs @@ -356,7 +356,7 @@ mod tests { impl AabbIntersection for Ray { fn intersects_aabb(&self, aabb: &Aabb) -> bool { - self.intersects_aabb(&aabb) + self.intersects_aabb(aabb) } }