From b31df43b23b6028fa6a20a1c4f08f4541cd9176a Mon Sep 17 00:00:00 2001 From: Mateusz Stulczewski Date: Wed, 16 Jul 2025 02:51:26 +0200 Subject: [PATCH] test: add tests for PlaneIntersectionMode --- crates/bevy_math/src/ray.rs | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/crates/bevy_math/src/ray.rs b/crates/bevy_math/src/ray.rs index 66e3fb8822..af8f0a7e86 100644 --- a/crates/bevy_math/src/ray.rs +++ b/crates/bevy_math/src/ray.rs @@ -213,4 +213,44 @@ mod tests { ) .is_none()); } + + #[test] + fn intersect_plane_3d_only_front() { + let ray = Ray3d::new(Vec3::ZERO, Dir3::Z); + + // Orthogonal, and test that ray intersects only the front face + assert_eq!( + ray.intersect_plane(Vec3::Z, InfinitePlane3d::new(Vec3::Z), PlaneIntersectionMode::FrontFaceOnly), + Some(1.0) + ); + assert!(ray + .intersect_plane(Vec3::Z, InfinitePlane3d::new(Vec3::NEG_Z), PlaneIntersectionMode::FrontFaceOnly) + .is_none()); + assert!(ray + .intersect_plane(Vec3::NEG_Z, InfinitePlane3d::new(Vec3::Z), PlaneIntersectionMode::FrontFaceOnly) + .is_none()); + assert!(ray + .intersect_plane(Vec3::NEG_Z, InfinitePlane3d::new(Vec3::Z), PlaneIntersectionMode::FrontFaceOnly) + .is_none()); + } + + #[test] + fn intersect_plane_3d_only_back() { + let ray = Ray3d::new(Vec3::ZERO, Dir3::Z); + + // Orthogonal, and test that ray intersects only the back face + assert!(ray + .intersect_plane(Vec3::Z, InfinitePlane3d::new(Vec3::Z), PlaneIntersectionMode::BackFaceOnly) + .is_none()); + assert_eq!( + ray.intersect_plane(Vec3::Z, InfinitePlane3d::new(Vec3::Z), PlaneIntersectionMode::BackFaceOnly), + Some(1.0) + ); + assert!(ray + .intersect_plane(Vec3::NEG_Z, InfinitePlane3d::new(Vec3::Z), PlaneIntersectionMode::BackFaceOnly) + .is_none()); + assert!(ray + .intersect_plane(Vec3::NEG_Z, InfinitePlane3d::new(Vec3::Z), PlaneIntersectionMode::BackFaceOnly) + .is_none()); + } }