Skip to content

Commit 3073f3a

Browse files
Bromeonlilizoey
authored andcommitted
Projection tests: fix is_equal_approx bug, reduce number of iterations
1 parent d6d73e4 commit 3073f3a

File tree

1 file changed

+82
-73
lines changed

1 file changed

+82
-73
lines changed

itest/rust/src/projection_test.rs

Lines changed: 82 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ fn matrix_eq_approx(a: Projection, b: Projection) -> bool {
1515
let v1 = a.cols[i];
1616
let v2 = b.cols[i];
1717
if !is_equal_approx(v1.x, v2.x)
18-
&& !is_equal_approx(v1.y, v2.y)
19-
&& !is_equal_approx(v1.z, v2.z)
20-
&& !is_equal_approx(v1.w, v2.w)
18+
|| !is_equal_approx(v1.y, v2.y)
19+
|| !is_equal_approx(v1.z, v2.z)
20+
|| !is_equal_approx(v1.w, v2.w)
2121
{
2222
return false;
2323
}
@@ -39,12 +39,12 @@ fn test_create_orthogonal() {
3939
for [left, right, bottom, top, near, far] in TEST_DATA {
4040
let rust_proj = Projection::create_orthogonal(left, right, bottom, top, near, far);
4141
let godot_proj = InnerProjection::create_orthogonal(
42-
left as _,
43-
right as _,
44-
bottom as _,
45-
top as _,
46-
near as _,
47-
far as _,
42+
left.as_f64(),
43+
right.as_f64(),
44+
bottom.as_f64(),
45+
top.as_f64(),
46+
near.as_f64(),
47+
far.as_f64(),
4848
);
4949

5050
assert_eq_approx!(
@@ -70,10 +70,10 @@ fn test_create_orthogonal_aspect() {
7070
for (size, aspect, near, far, flip_fov) in TEST_DATA {
7171
let rust_proj = Projection::create_orthogonal_aspect(size, aspect, near, far, flip_fov);
7272
let godot_proj = InnerProjection::create_orthogonal_aspect(
73-
size as _,
74-
aspect as _,
75-
near as _,
76-
far as _,
73+
size.as_f64(),
74+
aspect.as_f64(),
75+
near.as_f64(),
76+
far.as_f64(),
7777
flip_fov,
7878
);
7979

@@ -99,10 +99,10 @@ fn test_create_perspective() {
9999
for (fov_y, aspect, near, far, flip_fov) in TEST_DATA {
100100
let rust_proj = Projection::create_perspective(fov_y, aspect, near, far, flip_fov);
101101
let godot_proj = InnerProjection::create_perspective(
102-
fov_y as _,
103-
aspect as _,
104-
near as _,
105-
far as _,
102+
fov_y.as_f64(),
103+
aspect.as_f64(),
104+
near.as_f64(),
105+
far.as_f64(),
106106
flip_fov,
107107
);
108108

@@ -126,12 +126,12 @@ fn test_create_frustum() {
126126
for [left, right, bottom, top, near, far] in TEST_DATA {
127127
let rust_proj = Projection::create_frustum(left, right, bottom, top, near, far);
128128
let godot_proj = InnerProjection::create_frustum(
129-
left as _,
130-
right as _,
131-
bottom as _,
132-
top as _,
133-
near as _,
134-
far as _,
129+
left.as_f64(),
130+
right.as_f64(),
131+
bottom.as_f64(),
132+
top.as_f64(),
133+
near.as_f64(),
134+
far.as_f64(),
135135
);
136136

137137
assert_eq_approx!(
@@ -155,12 +155,13 @@ fn test_create_frustum_aspect() {
155155
for (size, aspect, offset, near, far, flip_fov) in TEST_DATA {
156156
let rust_proj =
157157
Projection::create_frustum_aspect(size, aspect, offset, near, far, flip_fov);
158+
158159
let godot_proj = InnerProjection::create_frustum_aspect(
159-
size as _,
160-
aspect as _,
160+
size.as_f64(),
161+
aspect.as_f64(),
161162
offset,
162-
near as _,
163-
far as _,
163+
near.as_f64(),
164+
far.as_f64(),
164165
flip_fov,
165166
);
166167

@@ -177,28 +178,32 @@ fn test_create_frustum_aspect() {
177178

178179
#[itest]
179180
fn test_projection_combined() {
181+
let range = [0, 5, 10, 15, 20];
182+
180183
fn f(v: isize) -> real {
181184
(v as real) * 0.5 - 0.5
182185
}
186+
183187
// Orthogonal
184-
for left_i in 0..20 {
188+
for left_i in range {
185189
let left = f(left_i);
186-
for right in (left_i + 1..=20).map(f) {
187-
for bottom_i in 0..20 {
190+
for right in range.map(|v| f(v + left_i)) {
191+
for bottom_i in range {
188192
let bottom = f(bottom_i);
189-
for top in (bottom_i + 1..=20).map(f) {
190-
for near_i in 0..20 {
193+
for top in range.map(|v| f(v + bottom_i)) {
194+
for near_i in range {
191195
let near = f(near_i);
192-
for far in (near_i + 1..=20).map(f) {
196+
for far in range.map(|v| f(v + near_i)) {
193197
let rust_proj =
194198
Projection::create_orthogonal(left, right, bottom, top, near, far);
199+
195200
let godot_proj = InnerProjection::create_orthogonal(
196-
left as _,
197-
right as _,
198-
bottom as _,
199-
top as _,
200-
near as _,
201-
far as _,
201+
left.as_f64(),
202+
right.as_f64(),
203+
bottom.as_f64(),
204+
top.as_f64(),
205+
near.as_f64(),
206+
far.as_f64(),
202207
);
203208

204209
assert_eq_approx!(
@@ -220,20 +225,21 @@ fn test_projection_combined() {
220225
}
221226

222227
// Perspective
223-
for fov_y in (0..18).map(|v| (v as real) * 10.0) {
224-
for aspect_x in 1..=10 {
225-
for aspect_y in 1..=10 {
228+
for fov_y in [3, 6, 12, 15].map(|v| (v as real) * 10.0) {
229+
for aspect_x in 1..=3 {
230+
for aspect_y in 1..=3 {
226231
let aspect = (aspect_x as real) / (aspect_y as real);
227-
for near_i in 1..10 {
232+
for near_i in 1..4 {
228233
let near = near_i as real;
229-
for far in (near_i + 1..=20).map(|v| v as real) {
234+
for far in range.map(|v| (v + near_i + 1) as real) {
230235
let rust_proj =
231236
Projection::create_perspective(fov_y, aspect, near, far, false);
237+
232238
let godot_proj = InnerProjection::create_perspective(
233-
fov_y as _,
234-
aspect as _,
235-
near as _,
236-
far as _,
239+
fov_y.as_f64(),
240+
aspect.as_f64(),
241+
near.as_f64(),
242+
far.as_f64(),
237243
false,
238244
);
239245

@@ -255,24 +261,25 @@ fn test_projection_combined() {
255261
}
256262

257263
// Frustum
258-
for left_i in 0..20 {
264+
for left_i in range {
259265
let left = f(left_i);
260-
for right in (left_i + 1..=20).map(f) {
261-
for bottom_i in 0..20 {
266+
for right in range.map(|v| f(v + left_i + 1)) {
267+
for bottom_i in range {
262268
let bottom = f(bottom_i);
263-
for top in (bottom_i + 1..=20).map(f) {
264-
for near_i in 0..20 {
269+
for top in range.map(|v| f(v + bottom_i + 1)) {
270+
for near_i in range {
265271
let near = (near_i as real) * 0.5;
266-
for far in (near_i + 1..=20).map(|v| (v as real) * 0.5) {
272+
for far in range.map(|v| ((v + near_i + 1) as real) * 0.5) {
267273
let rust_proj =
268274
Projection::create_frustum(left, right, bottom, top, near, far);
275+
269276
let godot_proj = InnerProjection::create_frustum(
270-
left as _,
271-
right as _,
272-
bottom as _,
273-
top as _,
274-
near as _,
275-
far as _,
277+
left.as_f64(),
278+
right.as_f64(),
279+
bottom.as_f64(),
280+
top.as_f64(),
281+
near.as_f64(),
282+
far.as_f64(),
276283
);
277284

278285
assert_eq_approx!(
@@ -294,13 +301,14 @@ fn test_projection_combined() {
294301
}
295302

296303
// Size, Aspect, Near, Far
297-
for size in (1..=10).map(|v| v as real) {
298-
for aspect_x in 1..=10 {
299-
for aspect_y in 1..=10 {
304+
let range = [1, 4, 7, 10];
305+
for size in range.map(|v| v as real) {
306+
for aspect_x in range {
307+
for aspect_y in range {
300308
let aspect = (aspect_x as real) / (aspect_y as real);
301-
for near_i in 1..10 {
309+
for near_i in range {
302310
let near = near_i as real;
303-
for far in (near_i + 1..=20).map(|v| v as real) {
311+
for far in range.map(|v| (v + near_i) as real) {
304312
let rust_proj_frustum = Projection::create_frustum_aspect(
305313
size,
306314
aspect,
@@ -310,11 +318,11 @@ fn test_projection_combined() {
310318
false,
311319
);
312320
let godot_proj_frustum = InnerProjection::create_frustum_aspect(
313-
size as _,
314-
aspect as _,
321+
size.as_f64(),
322+
aspect.as_f64(),
315323
Vector2::ZERO,
316-
near as _,
317-
far as _,
324+
near.as_f64(),
325+
far.as_f64(),
318326
false,
319327
);
320328

@@ -327,11 +335,12 @@ fn test_projection_combined() {
327335

328336
let rust_proj_ortho =
329337
Projection::create_orthogonal_aspect(size, aspect, near, far, false);
338+
330339
let godot_proj_ortho = InnerProjection::create_orthogonal_aspect(
331-
size as _,
332-
aspect as _,
333-
near as _,
334-
far as _,
340+
size.as_f64(),
341+
aspect.as_f64(),
342+
near.as_f64(),
343+
far.as_f64(),
335344
false,
336345
);
337346

0 commit comments

Comments
 (0)