Skip to content

Commit

Permalink
Rename AabbIntersection to IntersectsAabb.
Browse files Browse the repository at this point in the history
  • Loading branch information
finnbear committed Jan 7, 2025
1 parent 5b8c7a4 commit 15b4b0a
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions src/aabb/intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use crate::{aabb::Aabb, bounding_hierarchy::BHValue};

/// A trait implemented by things that may or may not intersect an AABB and, by extension,
/// things that can be used to traverse a BVH.
pub trait AabbIntersection<T: BHValue, const D: usize> {
pub trait IntersectsAabb<T: BHValue, const D: usize> {
/// Returns whether this object intersects an [`Aabb`].
///
/// # Examples
/// ```
/// use bvh::aabb::{Aabb, AabbIntersection};
/// use bvh::aabb::{Aabb, IntersectsAabb};
/// use nalgebra::Point3;
///
/// struct XyPlane;
///
/// impl AabbIntersection<f32,3> for XyPlane {
/// impl IntersectsAabb<f32,3> for XyPlane {
/// fn intersects_aabb(&self, aabb: &Aabb<f32,3>) -> bool {
/// aabb.min[2] <= 0.0 && aabb.max[2] >= 0.0
/// }
Expand All @@ -30,7 +30,7 @@ pub trait AabbIntersection<T: BHValue, const D: usize> {
fn intersects_aabb(&self, aabb: &Aabb<T, D>) -> bool;
}

impl<T: BHValue, const D: usize> AabbIntersection<T, D> for Aabb<T, D> {
impl<T: BHValue, const D: usize> IntersectsAabb<T, D> for Aabb<T, D> {
fn intersects_aabb(&self, aabb: &Aabb<T, D>) -> bool {
for i in 0..D {
if self.max[i] < aabb.min[i] || aabb.max[i] < self.min[i] {
Expand All @@ -41,7 +41,7 @@ impl<T: BHValue, const D: usize> AabbIntersection<T, D> for Aabb<T, D> {
}
}

impl<T: BHValue, const D: usize> AabbIntersection<T, D> for Point<T, D> {
impl<T: BHValue, const D: usize> IntersectsAabb<T, D> for Point<T, D> {
fn intersects_aabb(&self, aabb: &Aabb<T, D>) -> bool {
aabb.contains(self)
}
Expand Down
4 changes: 2 additions & 2 deletions src/ball.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Balls, including circles and spheres.
use crate::{
aabb::{Aabb, AabbIntersection},
aabb::{Aabb, IntersectsAabb},
bounding_hierarchy::BHValue,
};
use nalgebra::Point;
Expand All @@ -14,7 +14,7 @@ pub struct Ball<T: BHValue, const D: usize> {
pub radius: T,
}

impl<T: BHValue, const D: usize> AabbIntersection<T, D> for Ball<T, D> {
impl<T: BHValue, const D: usize> IntersectsAabb<T, D> for Ball<T, D> {
fn intersects_aabb(&self, aabb: &Aabb<T, D>) -> bool {
// https://gamemath.com/book/geomtests.html A.14
// Finding the point in/on the AABB that is closest to the ball's center or,
Expand Down
6 changes: 3 additions & 3 deletions src/bounding_hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use nalgebra::{
};
use num::{Float, FromPrimitive, Signed};

use crate::aabb::{AabbIntersection, Bounded};
use crate::aabb::{Bounded, IntersectsAabb};
#[cfg(feature = "rayon")]
use crate::bvh::rayon_executor;
use crate::bvh::BvhNodeBuildArgs;
Expand Down Expand Up @@ -239,7 +239,7 @@ pub trait BoundingHierarchy<T: BHValue, const D: usize> {
/// [`BoundingHierarchy`]: trait.BoundingHierarchy.html
/// [`Aabb`]: ../aabb/struct.Aabb.html
///
fn traverse<'a, Query: AabbIntersection<T, D>, Shape: BHShape<T, D>>(
fn traverse<'a, Query: IntersectsAabb<T, D>, Shape: BHShape<T, D>>(
&'a self,
query: &Query,
shapes: &'a [Shape],
Expand All @@ -257,7 +257,7 @@ impl<T: BHValue, const D: usize, H: BoundingHierarchy<T, D>> BoundingHierarchy<T
Box::new(H::build(shapes))
}

fn traverse<'a, Query: AabbIntersection<T, D>, Shape: BHShape<T, D>>(
fn traverse<'a, Query: IntersectsAabb<T, D>, Shape: BHShape<T, D>>(
&'a self,
query: &Query,
shapes: &'a [Shape],
Expand Down
10 changes: 5 additions & 5 deletions src/bvh/bvh_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! [`BvhNode`]: struct.BvhNode.html
//!
use crate::aabb::{Aabb, AabbIntersection, Bounded};
use crate::aabb::{Aabb, Bounded, IntersectsAabb};
use crate::bounding_hierarchy::{BHShape, BHValue, BoundingHierarchy};
use crate::bvh::iter::BvhTraverseIterator;
use crate::ray::Ray;
Expand Down Expand Up @@ -97,7 +97,7 @@ impl<T: BHValue, const D: usize> Bvh<T, D> {
/// [`Bvh`]: struct.Bvh.html
/// [`Aabb`]: ../aabb/struct.Aabb.html
///
pub fn traverse<'a, Query: AabbIntersection<T, D>, Shape: Bounded<T, D>>(
pub fn traverse<'a, Query: IntersectsAabb<T, D>, Shape: Bounded<T, D>>(
&'a self,
query: &Query,
shapes: &'a [Shape],
Expand All @@ -116,12 +116,12 @@ impl<T: BHValue, const D: usize> Bvh<T, D> {

/// Creates a [`BvhTraverseIterator`] to traverse the [`Bvh`].
/// Returns a subset of `shapes`, in which the [`Aabb`]s of the elements for which
/// [`AabbIntersection::intersects_aabb`] returns `true`.
/// [`IntersectsAabb::intersects_aabb`] returns `true`.
///
/// [`Bvh`]: struct.Bvh.html
/// [`Aabb`]: ../aabb/struct.Aabb.html
///
pub fn traverse_iterator<'bvh, 'shape, Query: AabbIntersection<T, D>, Shape: Bounded<T, D>>(
pub fn traverse_iterator<'bvh, 'shape, Query: IntersectsAabb<T, D>, Shape: Bounded<T, D>>(
&'bvh self,
query: &'bvh Query,
shapes: &'shape [Shape],
Expand Down Expand Up @@ -410,7 +410,7 @@ impl<T: BHValue + std::fmt::Display, const D: usize> BoundingHierarchy<T, D> for
Bvh::build(shapes)
}

fn traverse<'a, Query: AabbIntersection<T, D>, Shape: Bounded<T, D>>(
fn traverse<'a, Query: IntersectsAabb<T, D>, Shape: Bounded<T, D>>(
&'a self,
query: &Query,
shapes: &'a [Shape],
Expand Down
4 changes: 2 additions & 2 deletions src/bvh/bvh_node.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::aabb::{Aabb, AabbIntersection};
use crate::aabb::{Aabb, IntersectsAabb};
use crate::bounding_hierarchy::{BHShape, BHValue};
use crate::utils::{joint_aabb_of_shapes, Bucket};
use std::cell::RefCell;
Expand Down Expand Up @@ -291,7 +291,7 @@ impl<T: BHValue, const D: usize> BvhNode<T, D> {
/// [`Bvh`]: struct.Bvh.html
/// [`Ray`]: ../ray/struct.Ray.html
///
pub fn traverse_recursive<Query: AabbIntersection<T, D>>(
pub fn traverse_recursive<Query: IntersectsAabb<T, D>>(
nodes: &[BvhNode<T, D>],
node_index: usize,
query: &Query,
Expand Down
10 changes: 5 additions & 5 deletions src/bvh/iter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::aabb::{AabbIntersection, Bounded};
use crate::aabb::{Bounded, IntersectsAabb};
use crate::bounding_hierarchy::BHValue;
use crate::bvh::{Bvh, BvhNode};

Expand All @@ -8,7 +8,7 @@ pub struct BvhTraverseIterator<
'shape,
T: BHValue,
const D: usize,
Query: AabbIntersection<T, D>,
Query: IntersectsAabb<T, D>,
Shape: Bounded<T, D>,
> {
/// Reference to the [`Bvh`] to traverse
Expand All @@ -32,7 +32,7 @@ impl<
'shape,
T: BHValue,
const D: usize,
Query: AabbIntersection<T, D>,
Query: IntersectsAabb<T, D>,
Shape: Bounded<T, D>,
> BvhTraverseIterator<'bvh, 'shape, T, D, Query, Shape>
{
Expand Down Expand Up @@ -119,8 +119,8 @@ impl<
}
}

impl<'shape, T: BHValue, const D: usize, Query: AabbIntersection<T, D>, Shape: Bounded<T, D>>
Iterator for BvhTraverseIterator<'_, 'shape, T, D, Query, Shape>
impl<'shape, T: BHValue, const D: usize, Query: IntersectsAabb<T, D>, Shape: Bounded<T, D>> Iterator
for BvhTraverseIterator<'_, 'shape, T, D, Query, Shape>
{
type Item = &'shape Shape;

Expand Down
4 changes: 2 additions & 2 deletions src/flat_bvh.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This module exports methods to flatten the [`Bvh`] into a [`FlatBvh`] and traverse it iteratively.
use crate::aabb::{Aabb, AabbIntersection, Bounded};
use crate::aabb::{Aabb, Bounded, IntersectsAabb};
use crate::bounding_hierarchy::{BHShape, BHValue, BoundingHierarchy};
use crate::bvh::{Bvh, BvhNode};

Expand Down Expand Up @@ -381,7 +381,7 @@ impl<T: BHValue + std::fmt::Display, const D: usize> BoundingHierarchy<T, D> for
/// let flat_bvh = FlatBvh::build(&mut shapes);
/// let hit_shapes = flat_bvh.traverse(&ray, &shapes);
/// ```
fn traverse<'a, Q: AabbIntersection<T, D>, B: Bounded<T, D>>(
fn traverse<'a, Q: IntersectsAabb<T, D>, B: Bounded<T, D>>(
&'a self,
query: &Q,
shapes: &'a [B],
Expand Down
4 changes: 2 additions & 2 deletions src/ray/ray_impl.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module defines a Ray structure and intersection algorithms
//! for axis aligned bounding boxes and triangles.
use crate::aabb::AabbIntersection;
use crate::aabb::IntersectsAabb;
use crate::utils::{fast_max, fast_min};
use crate::{aabb::Aabb, bounding_hierarchy::BHValue};
use nalgebra::{
Expand Down Expand Up @@ -354,7 +354,7 @@ mod tests {
}
}

impl<T: BHValue, const D: usize> AabbIntersection<T, D> for Ray<T, D> {
impl<T: BHValue, const D: usize> IntersectsAabb<T, D> for Ray<T, D> {
fn intersects_aabb(&self, aabb: &Aabb<T, D>) -> bool {
self.intersects_aabb(aabb)
}
Expand Down

0 comments on commit 15b4b0a

Please sign in to comment.