Commit 2ce3d9fc authored by Philip Trettner's avatar Philip Trettner
Browse files

ray-triangle intersection tets

parent ae3e28d8
Pipeline #13534 failed with stage
in 7 minutes and 8 seconds
ctracer @ 4c0cc17a
Subproject commit f5c89c5aecf75079a2d1314ebeb9020f1f091bcb
Subproject commit 4c0cc17a7408c7e806535c59782fe64768934a8c
typed-geometry @ 9849f4f0
Subproject commit fabd052a0bcd32b45b030d4b3f5e81f740dba0e6
Subproject commit 9849f4f05262ca94a55a3027ea04d5e38f62d542
......@@ -310,3 +310,76 @@ TEST_CASE("TypedGeometry.IntersectionCircle2Circle2")
CHECK(res.value().second.y == approx(tg::sqrt(0.75f)));
}
}
TG_FUZZ_TEST(Triangle, Intersection)
{
auto bb = tg::aabb3(-10, 10);
auto v0 = uniform(rng, bb);
auto v1 = uniform(rng, bb);
auto v2 = uniform(rng, bb);
auto origin = uniform(rng, bb);
auto t0 = tg::triangle(v0, v1, v2);
auto t1 = tg::triangle(v1, v2, v0);
auto t2 = tg::triangle(v2, v0, v1);
auto t3 = tg::triangle(v2, v1, v0);
auto t4 = tg::triangle(v1, v0, v2);
auto t5 = tg::triangle(v0, v2, v1);
auto p = uniform(rng, t0);
auto rdir = normalize(p - origin);
auto ray = tg::ray(origin, rdir);
auto nray = tg::ray(origin, -rdir);
CHECK(tg::intersects(ray, t0));
CHECK(tg::intersects(ray, t1));
CHECK(tg::intersects(ray, t2));
CHECK(tg::intersects(ray, t3));
CHECK(tg::intersects(ray, t4));
CHECK(tg::intersects(ray, t5));
CHECK(tg::intersects(ray, tg::plane3(rdir, p)));
CHECK(tg::intersects(ray, tg::plane3(-rdir, p)));
CHECK(!tg::intersects(nray, t0));
CHECK(!tg::intersects(nray, t1));
CHECK(!tg::intersects(nray, t2));
CHECK(!tg::intersects(nray, t3));
CHECK(!tg::intersects(nray, t4));
CHECK(!tg::intersects(nray, t5));
CHECK(!tg::intersects(nray, tg::plane3(rdir, p)));
CHECK(!tg::intersects(nray, tg::plane3(-rdir, p)));
auto ip0 = tg::intersection(ray, t0);
auto ip1 = tg::intersection(ray, t1);
auto ip2 = tg::intersection(ray, t2);
auto ip3 = tg::intersection(ray, t3);
auto ip4 = tg::intersection(ray, t4);
auto ip5 = tg::intersection(ray, t5);
CHECK(ip0.has_value());
CHECK(ip1.has_value());
CHECK(ip2.has_value());
CHECK(ip3.has_value());
CHECK(ip4.has_value());
CHECK(ip5.has_value());
CHECK(ip0.value() == approx(p, 0.01f));
CHECK(ip1.value() == approx(p, 0.01f));
CHECK(ip2.value() == approx(p, 0.01f));
CHECK(ip3.value() == approx(p, 0.01f));
CHECK(ip4.value() == approx(p, 0.01f));
CHECK(ip5.value() == approx(p, 0.01f));
auto a = uniform(rng, -2.f, 2.f);
auto b = uniform(rng, -2.f, 2.f);
auto c = 1 - a - b;
auto p2 = t0[{a,b,c}];
auto rdir2 = normalize(p2 - origin);
auto ray2 = tg::ray(origin, rdir2);
auto nray2 = tg::ray(origin, -rdir2);
CHECK(!tg::intersects(nray2, t0));
if (a < 0 || b < 0 || c < 0)
CHECK(!tg::intersects(ray2, t0));
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment