Commit 34de1cf9 authored by Julian Schakib's avatar Julian Schakib
Browse files

new tg and ray-polyhedron intersection

parent c2dcb196
typed-geometry @ a33202c3
Subproject commit 9349e3d864155f776460192952e58a24ad96dc3b
Subproject commit a33202c369b576d1b3844277e7e3df8db807688d
......@@ -2,6 +2,53 @@
#include <typed-geometry/tg-std.hh>
TG_FUZZ_TEST(TypedGeometry, IntersectionRay3Polyhedron)
{
// six sided cube as polyhedron
auto halfext = uniform(rng, 1.0f, 5.0f) / 2;
// TODO - or + halfext?
auto p0 = tg::plane(tg::dir3::pos_y, halfext);
auto p1 = tg::plane(tg::dir3::neg_y, halfext);
auto p2 = tg::plane(tg::dir3::pos_x, halfext);
auto p3 = tg::plane(tg::dir3::neg_x, halfext);
auto p4 = tg::plane(tg::dir3::pos_z, halfext);
auto p5 = tg::plane(tg::dir3::neg_z, halfext);
auto box = tg::aabb3(tg::pos3(-halfext), tg::pos3(halfext));
auto cube = tg::polyhedron<6, tg::f32>({p0, p1, p2, p3, p4, p5});
{
auto ray = tg::ray(tg::pos3::zero, tg::dir3::neg_x);
CHECK(tg::intersects(ray, cube));
CHECK(tg::intersects(ray, box));
}
{
auto ray = tg::ray(tg::pos3(halfext * 2), normalize(tg::vec3(0.2f, 1, 0)));
// TODO fails!!
CHECK(!tg::intersects(ray, cube));
CHECK(!tg::intersects(ray, box));
}
// auto ray = tg::ray(uniform(rng, tg::aabb3(tg::pos3(-10), tg::pos3(10))), normalize(tg::vec3(uniform(rng, tg::aabb3(tg::pos3(-10), tg::pos3(10))))));
{
auto ray = tg::ray3(uniform(rng, box), normalize(tg::vec3(uniform(rng, box))));
CHECK(tg::intersects(ray, cube) == tg::intersects(ray, box));
}
{
auto box2 = tg::aabb3(box.min * 2, box.max * 2);
auto out = tg::pos3::zero;
while (tg::contains(box, out))
out = uniform(rng, box2);
auto ray = tg::ray3(out, normalize(-tg::vec3(out)));
CHECK(tg::intersects(ray, box));
CHECK(tg::intersects(ray, cube));
}
}
TG_FUZZ_TEST(TypedGeometry, IntersectionRay3AABB3)
{
auto box3 = tg::aabb3(tg::pos3(0.0f), tg::pos3(10.0f));
......@@ -34,6 +81,12 @@ TG_FUZZ_TEST(TypedGeometry, IntersectionRay3AABB3)
auto ray = tg::ray3(aabb.max + tg::dir3::pos_x * 0.1f, tg::dir3::neg_x);
CHECK(tg::intersects(ray, aabb, tg::f32(0.01f)));
}
// ray inside box
{
auto ray = tg::ray3(uniform(rng, aabb), normalize(tg::vec3(uniform(rng, aabb))));
CHECK(tg::intersects(ray, aabb));
}
}
TG_FUZZ_TEST(TypedGeometry, IntersectionRay3InfCone3)
......
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