math: Add more precise triangleIntersect tests
This commit is contained in:
parent
8ddb9ade70
commit
efe9d3d5d2
1 changed files with 92 additions and 0 deletions
|
|
@ -259,3 +259,95 @@ test "triangleIntersect_basic_backface_bc_miss" {
|
||||||
|
|
||||||
try testing.expect(?math.Ray.Hit, null).eql(result);
|
try testing.expect(?math.Ray.Hit, null).eql(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "triangleIntersect_precise_frontface_bc_hit_f32" {
|
||||||
|
const a: math.Vec3 = math.vec3(
|
||||||
|
3164.91,
|
||||||
|
3559.55,
|
||||||
|
3044.54,
|
||||||
|
);
|
||||||
|
const b: math.Vec3 = math.vec3(
|
||||||
|
1011.92,
|
||||||
|
3113.34,
|
||||||
|
3674.56,
|
||||||
|
);
|
||||||
|
const c: math.Vec3 = math.vec3(
|
||||||
|
503.804,
|
||||||
|
2311.16,
|
||||||
|
2449.58,
|
||||||
|
);
|
||||||
|
const ray0: math.Ray = math.Ray{
|
||||||
|
.origin = math.vec3(
|
||||||
|
293.293,
|
||||||
|
264.527,
|
||||||
|
225.465,
|
||||||
|
),
|
||||||
|
.direction = math.vec3(
|
||||||
|
0.439063,
|
||||||
|
0.652555,
|
||||||
|
0.617573,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
const result: math.Ray.Hit = ray0.triangleIntersect(
|
||||||
|
&a,
|
||||||
|
&b,
|
||||||
|
&c,
|
||||||
|
true,
|
||||||
|
).?;
|
||||||
|
|
||||||
|
const expected_t: f32 = 4606.98;
|
||||||
|
const expected_u: f32 = 0.643925;
|
||||||
|
const expected_v: f32 = 0.194228;
|
||||||
|
const expected_w: f32 = 0.161846;
|
||||||
|
try testing.expect(f32, expected_u).eqlApprox(result.v[0], 1e-5);
|
||||||
|
try testing.expect(f32, expected_v).eqlApprox(result.v[1], 1e-5);
|
||||||
|
try testing.expect(f32, expected_w).eqlApprox(result.v[2], 1e-5);
|
||||||
|
try testing.expect(f32, expected_t).eqlApprox(result.v[3], 1e-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
test "triangleIntersect_precise_frontface_bc_hit_f64" {
|
||||||
|
const a: math.Vec3d = math.vec3d(
|
||||||
|
2371.01,
|
||||||
|
3208.12,
|
||||||
|
1570.04,
|
||||||
|
);
|
||||||
|
const b: math.Vec3d = math.vec3d(
|
||||||
|
1412.2,
|
||||||
|
2978.36,
|
||||||
|
1501.33,
|
||||||
|
);
|
||||||
|
const c: math.Vec3d = math.vec3d(
|
||||||
|
2520.99,
|
||||||
|
3323.93,
|
||||||
|
1567.18,
|
||||||
|
);
|
||||||
|
const ray0: math.Rayd = math.Rayd{
|
||||||
|
.origin = math.vec3d(
|
||||||
|
246.713,
|
||||||
|
279.646,
|
||||||
|
180.443,
|
||||||
|
),
|
||||||
|
.direction = math.vec3d(
|
||||||
|
0.497991,
|
||||||
|
0.782698,
|
||||||
|
0.373349,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
const result: math.Rayd.Hit = ray0.triangleIntersect(
|
||||||
|
&a,
|
||||||
|
&b,
|
||||||
|
&c,
|
||||||
|
true,
|
||||||
|
).?;
|
||||||
|
|
||||||
|
const expected_t: f64 = 3660.17;
|
||||||
|
const expected_u: f64 = 0.56102;
|
||||||
|
const expected_v: f64 = 0.33136;
|
||||||
|
const expected_w: f64 = 0.10761;
|
||||||
|
try testing.expect(f64, expected_u).eqlApprox(result.v[0], 1e-4);
|
||||||
|
try testing.expect(f64, expected_v).eqlApprox(result.v[1], 1e-4);
|
||||||
|
try testing.expect(f64, expected_w).eqlApprox(result.v[2], 1e-4);
|
||||||
|
try testing.expect(f64, expected_t).eqlApprox(result.v[3], 1e-2);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue