Skip to content

Commit 9ba3545

Browse files
committed
itest: rust: src: Plane integration tests implementation
1 parent 9e6a8a0 commit 9ba3545

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

itest/rust/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mod node_test;
2727
mod object_test;
2828
mod option_ffi_test;
2929
mod packed_array_test;
30+
mod plane_test;
3031
mod projection_test;
3132
mod quaternion_test;
3233
mod rect2i_test;

itest/rust/src/plane_test.rs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
*/
6+
7+
use std::fmt::Debug;
8+
9+
use crate::itest;
10+
use godot::prelude::{inner::InnerPlane, real, Plane, Vector3};
11+
12+
#[itest]
13+
fn plane_equiv_unary() {
14+
let test_planes = [
15+
Plane::new(Vector3::UP.normalized(), 0.0),
16+
Plane::new(Vector3::BACK.normalized(), 0.0),
17+
Plane::new(Vector3::new(1.5, 3.0, 0.0).normalized(), 2.0),
18+
Plane::new(Vector3::new(0.5, 2.0, 2.5).normalized(), 1.0),
19+
Plane::new(Vector3::new(-3.0, 5.0, 0.1).normalized(), -0.2),
20+
Plane::new(Vector3::new(1.82, 5.32, -6.1).normalized(), 6.0),
21+
Plane::new(Vector3::new(1.82, 5.32, -6.000001).normalized(), 6.0),
22+
];
23+
let test_vectors = [
24+
Vector3::ZERO,
25+
Vector3::new(0.0, 3.0, 2.0),
26+
Vector3::new(6.1, 8.0, 9.0),
27+
Vector3::new(2.0, 1.0, -2.0),
28+
Vector3::new(5.2, 2.0, -1.0),
29+
Vector3::new(7.0, -3.0, -0.15),
30+
Vector3::new(0.0, 0.0, 0.0001),
31+
Vector3::new(0.0, 0.0, 0.000001),
32+
Vector3::new(real::INFINITY, 0.0, -9.0),
33+
];
34+
let test_reals = [1.0, 0.0005, 0.000005, 0.0000001, 0.0];
35+
let test_inf_planes = [
36+
Plane {
37+
normal: Vector3::new(real::INFINITY, 0.0, 0.0),
38+
d: 10.0,
39+
},
40+
Plane {
41+
normal: Vector3::new(real::NAN, real::INFINITY, real::NEG_INFINITY),
42+
d: real::NAN,
43+
},
44+
Plane {
45+
normal: Vector3::new(0.8, real::INFINITY, -1.2),
46+
d: 3.5,
47+
},
48+
];
49+
50+
fn check_mapping_eq<T>(context: &str, outer: T, inner: T)
51+
where
52+
T: PartialEq + Debug,
53+
{
54+
assert_eq!(
55+
outer, inner,
56+
"{context}: outer != inner ({outer:?} != {inner:?})"
57+
);
58+
}
59+
60+
for a in test_planes {
61+
let inner_a = InnerPlane::from_outer(&a);
62+
63+
check_mapping_eq("center", a.center(), inner_a.get_center());
64+
check_mapping_eq("is_finite", a.is_finite(), inner_a.is_finite());
65+
66+
for b in test_inf_planes {
67+
let inner_b = InnerPlane::from_outer(&b);
68+
check_mapping_eq("is_finite", b.is_finite(), inner_b.is_finite());
69+
}
70+
71+
check_mapping_eq("normalized", a.normalized(), inner_a.normalized());
72+
73+
for b in test_vectors {
74+
check_mapping_eq(
75+
"distance_to",
76+
a.distance_to(b) as f64,
77+
inner_a.distance_to(b),
78+
);
79+
check_mapping_eq(
80+
"is_point_over",
81+
a.is_point_over(b),
82+
inner_a.is_point_over(b),
83+
);
84+
check_mapping_eq("project", a.project(b), inner_a.project(b));
85+
for c in test_vectors {
86+
check_mapping_eq(
87+
"intersect_segment",
88+
a.intersect_segment(b, c).unwrap_or_default(),
89+
inner_a.intersects_segment(b, c).to(),
90+
);
91+
check_mapping_eq(
92+
"intersect_ray",
93+
a.intersect_ray(b, c).unwrap_or_default(),
94+
inner_a.intersects_ray(b, c).to(),
95+
);
96+
}
97+
for c in test_reals {
98+
check_mapping_eq(
99+
"contains_point",
100+
a.contains_point(b, Some(c)),
101+
inner_a.has_point(b, c.into()),
102+
);
103+
}
104+
}
105+
106+
for b in test_planes {
107+
check_mapping_eq(
108+
"is_equal_approx",
109+
a.is_equal_approx(&b),
110+
inner_a.is_equal_approx(b),
111+
);
112+
for c in test_planes {
113+
check_mapping_eq(
114+
"intersect_3",
115+
a.intersect_3(&b, &c).unwrap_or_default(),
116+
inner_a.intersect_3(b, c).to(),
117+
);
118+
}
119+
}
120+
}
121+
}

0 commit comments

Comments
 (0)