Skip to content

Commit

Permalink
Test Ball::contains.
Browse files Browse the repository at this point in the history
  • Loading branch information
finnbear committed Jan 7, 2025
1 parent 38e4143 commit bb2d0ae
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/ball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<T: BHValue, const D: usize> Ball<T, D> {
for i in 0..D {
distance_squared += (point[i] - self.center[i]).powi(2);
}
distance_squared.sqrt()
distance_squared <= self.radius.powi(2)
}
}

Expand All @@ -57,3 +57,17 @@ impl<T: BHValue, const D: usize> IntersectsAabb<T, D> for Ball<T, D> {
distance_squared <= self.radius.powi(2)
}
}

#[cfg(test)]
mod tests {
use nalgebra::Point;

use super::Ball;

#[test]
fn ball_contains() {
let ball = Ball::new(Point::<f32, 3>::new(3.0, 4.0, 5.0), 2.0);
assert!(ball.contains(&Point::<f32, 3>::new(4.0, 4.0, 5.0)));
assert!(!ball.contains(&Point::<f32, 3>::new(-4.0, 4.0, 5.0)));
}
}

0 comments on commit bb2d0ae

Please sign in to comment.