From 77c59c22abf6a1f93d254e18684d347d3c53d651 Mon Sep 17 00:00:00 2001 From: ira Date: Mon, 5 Dec 2022 22:49:06 +0000 Subject: [PATCH] Improve code/comments for `Ray::intersect_plane` and its tests (#6823) Co-authored-by: devil-ira --- crates/bevy_math/src/ray.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/bevy_math/src/ray.rs b/crates/bevy_math/src/ray.rs index a755465dc1470..b4d8e7b03f5a8 100644 --- a/crates/bevy_math/src/ray.rs +++ b/crates/bevy_math/src/ray.rs @@ -17,7 +17,7 @@ impl Ray { let denominator = plane_normal.dot(self.direction); if denominator.abs() > f32::EPSILON { let distance = (plane_origin - self.origin).dot(plane_normal) / denominator; - if distance >= f32::EPSILON { + if distance > f32::EPSILON { return Some(distance); } } @@ -32,17 +32,17 @@ impl Ray { } #[cfg(test)] -mod test { +mod tests { use super::*; #[test] - fn intersects_plane() { + fn intersect_plane() { let ray = Ray { origin: Vec3::ZERO, direction: Vec3::Z, }; - // Orthogonal, and test that plane_normal direction doesn't matter + // Orthogonal, and test that an inverse plane_normal has the same result assert_eq!(Some(1.), ray.intersect_plane(Vec3::Z, Vec3::Z)); assert_eq!(Some(1.), ray.intersect_plane(Vec3::Z, Vec3::NEG_Z)); assert_eq!(None, ray.intersect_plane(Vec3::NEG_Z, Vec3::Z)); @@ -52,10 +52,10 @@ mod test { assert_eq!(Some(1.), ray.intersect_plane(Vec3::Z, Vec3::ONE)); assert_eq!(None, ray.intersect_plane(Vec3::NEG_Z, Vec3::ONE)); - // Parralel + // Parallel assert_eq!(None, ray.intersect_plane(Vec3::X, Vec3::X)); - // Parralel with simulated rounding error + // Parallel with simulated rounding error assert_eq!( None, ray.intersect_plane(Vec3::X, Vec3::X + Vec3::Z * f32::EPSILON)