From 748e783f1ebc2f04d43e5a27ab66e944e1ddcee8 Mon Sep 17 00:00:00 2001 From: Serkyo Date: Thu, 23 Jul 2026 02:11:50 +0200 Subject: [PATCH] test(renderer): relocate frustum tests into src/tests --- crates/renderer/src/frustum.rs | 39 ++-------------------------- crates/renderer/src/tests/frustum.rs | 39 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 crates/renderer/src/tests/frustum.rs diff --git a/crates/renderer/src/frustum.rs b/crates/renderer/src/frustum.rs index d50083c..becdcc5 100644 --- a/crates/renderer/src/frustum.rs +++ b/crates/renderer/src/frustum.rs @@ -62,40 +62,5 @@ impl Frustum { } #[cfg(test)] -mod tests { - use super::Frustum; - use glam::Vec3; - - /// Builds a frustum for a camera at the origin looking down the -Z axis, matching the engine's right-handed Vulkan-clip projection. - fn forward_facing_frustum() -> Frustum { - let proj = glam::camera::rh::proj::vulkan::perspective(60f32.to_radians(), 1.0, 0.1, 100.0); - let view = glam::camera::rh::view::look_at_mat4(Vec3::ZERO, Vec3::NEG_Z, Vec3::Y); - Frustum::from_view_proj(proj * view) - } - - #[test] - fn box_in_front_is_visible() { - let frustum = forward_facing_frustum(); - assert!(frustum.intersects_aabb(Vec3::new(-1.0, -1.0, -6.0), Vec3::new(1.0, 1.0, -4.0))); - } - - #[test] - fn box_behind_camera_is_culled() { - // A box entirely behind the camera. This is the case that fails if the near plane is extracted with the OpenGL `r3 + r2` formula instead of `r2`. - let frustum = forward_facing_frustum(); - assert!(!frustum.intersects_aabb(Vec3::new(-1.0, -1.0, 4.0), Vec3::new(1.0, 1.0, 6.0))); - } - - #[test] - fn box_far_to_the_side_is_culled() { - // Well outside the horizontal field of view at an otherwise valid depth. - let frustum = forward_facing_frustum(); - assert!(!frustum.intersects_aabb(Vec3::new(50.0, -1.0, -5.0), Vec3::new(52.0, 1.0, -4.0))); - } - - #[test] - fn huge_box_straddling_origin_is_visible() { - let frustum = forward_facing_frustum(); - assert!(frustum.intersects_aabb(Vec3::splat(-100.0), Vec3::splat(100.0))); - } -} +#[path = "tests/frustum.rs"] +mod tests; diff --git a/crates/renderer/src/tests/frustum.rs b/crates/renderer/src/tests/frustum.rs new file mode 100644 index 0000000..56233e4 --- /dev/null +++ b/crates/renderer/src/tests/frustum.rs @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: AGPL-3.0-only + +//! Unit tests for view-frustum culling in [`crate::frustum`]. + +use super::Frustum; +use glam::Vec3; + +/// Builds a frustum for a camera at the origin looking down the -Z axis, matching the engine's right-handed Vulkan-clip projection. +fn forward_facing_frustum() -> Frustum { + let proj = glam::camera::rh::proj::vulkan::perspective(60f32.to_radians(), 1.0, 0.1, 100.0); + let view = glam::camera::rh::view::look_at_mat4(Vec3::ZERO, Vec3::NEG_Z, Vec3::Y); + Frustum::from_view_proj(proj * view) +} + +#[test] +fn box_in_front_is_visible() { + let frustum = forward_facing_frustum(); + assert!(frustum.intersects_aabb(Vec3::new(-1.0, -1.0, -6.0), Vec3::new(1.0, 1.0, -4.0))); +} + +#[test] +fn box_behind_camera_is_culled() { + // A box entirely behind the camera. This is the case that fails if the near plane is extracted with the OpenGL `r3 + r2` formula instead of `r2`. + let frustum = forward_facing_frustum(); + assert!(!frustum.intersects_aabb(Vec3::new(-1.0, -1.0, 4.0), Vec3::new(1.0, 1.0, 6.0))); +} + +#[test] +fn box_far_to_the_side_is_culled() { + // Well outside the horizontal field of view at an otherwise valid depth. + let frustum = forward_facing_frustum(); + assert!(!frustum.intersects_aabb(Vec3::new(50.0, -1.0, -5.0), Vec3::new(52.0, 1.0, -4.0))); +} + +#[test] +fn huge_box_straddling_origin_is_visible() { + let frustum = forward_facing_frustum(); + assert!(frustum.intersects_aabb(Vec3::splat(-100.0), Vec3::splat(100.0))); +}