From 13f36e785ad8b9d9c831c8f252bdca4396e3bdac Mon Sep 17 00:00:00 2001 From: Daniel Oom Date: Tue, 26 Mar 2024 21:59:30 +0100 Subject: [PATCH] Add kdtree build test for non-axially aligned triangle --- kdtree/src/build_sah.rs | 49 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/kdtree/src/build_sah.rs b/kdtree/src/build_sah.rs index 0210dd5c..33b22213 100644 --- a/kdtree/src/build_sah.rs +++ b/kdtree/src/build_sah.rs @@ -139,7 +139,54 @@ mod tests { use super::*; #[test] - fn test() { + fn test_non_axially_aligned_triangle() { + let triangles = vec![Triangle { + v0: Vector3::new(0.0, 0.0, 0.0), + v1: Vector3::new(1.0, 0.0, 0.0), + v2: Vector3::new(1.0, 1.0, 1.0), + }]; + let builder = SahKdTreeBuilder { + traverse_cost: 0.1, + intersect_cost: 1.0, + empty_factor: 0.8, + triangles, + }; + let tree = build_kdtree(builder, 10); + + let expected = KdNode::new_node( + Aap::new_x(0.0), + KdNode::empty(), + KdNode::new_node( + Aap::new_x(1.0), + KdNode::new_node( + Aap::new_y(0.0), + KdNode::empty(), + KdNode::new_node( + Aap::new_y(1.0), + KdNode::new_node( + Aap::new_z(0.0), + KdNode::empty(), + KdNode::new_node( + Aap::new_z(1.0), + KdNode::new_leaf(vec![0]), + KdNode::empty(), + ), + ), + KdNode::empty(), + ), + ), + KdNode::empty(), + ), + ); + assert_eq!( + tree.root, expected, + "\n actual: {}\n expected: {}", + tree.root, expected + ); + } + + #[test] + fn test_axially_aligned_triangle() { let triangles = vec![Triangle { v0: Vector3::new(0.0, 0.0, 0.0), v1: Vector3::new(1.0, 0.0, 0.0),