Skip to content

Commit

Permalink
Add kdtree build test for non-axially aligned triangle
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Oom committed Mar 26, 2024
1 parent a66b45f commit 13f36e7
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion kdtree/src/build_sah.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 13f36e7

Please sign in to comment.