Skip to content
Snippets Groups Projects

Added random sampling test case

Merged Julius Nehring-Wirxel requested to merge test/aabb-intersect-sampling into develop
1 file
+ 77
23
Compare changes
  • Side-by-side
  • Inline
@@ -5,22 +5,13 @@ TG_FUZZ_TEST(AABB, Intersect)
auto const bounds = tg::aabb3(-10, 10);
{
auto const min_a = tg::uniform(rng, bounds);
auto const max_a = tg::uniform(rng, tg::aabb3(min_a, bounds.max));
auto const min_a = uniform(rng, bounds);
auto const max_a = uniform(rng, tg::aabb3(min_a, bounds.max));
auto const aabb_a = tg::aabb3(min_a, max_a);
tg::pos3 inside;
do
{
// must be truly inside
inside = tg::uniform(rng, aabb_a);
} while (aabb_a.min.x >= inside.x || inside.x >= aabb_a.max.x || //
aabb_a.min.y >= inside.y || inside.y >= aabb_a.max.y || //
aabb_a.min.z >= inside.z || inside.z >= aabb_a.max.z);
auto const other = tg::uniform(rng, bounds);
auto const inside = uniform(rng, aabb_a);
auto const other = uniform(rng, bounds);
const tg::pos3 min_b = {
tg::min(inside.x, other.x),
@@ -46,26 +37,26 @@ TG_FUZZ_TEST(AABB, NonIntersect)
auto const bounds = tg::aabb3(-10, 10);
{
auto const min_a = tg::uniform(rng, bounds);
auto const max_a = tg::uniform(rng, tg::aabb3(min_a, bounds.max));
auto const min_a = uniform(rng, bounds);
auto const max_a = uniform(rng, tg::aabb3(min_a, bounds.max));
auto const aabb_a = tg::aabb3(min_a, max_a);
auto min_b = tg::uniform(rng, bounds);
auto max_b = tg::uniform(rng, tg::aabb3(min_b, bounds.max));
auto min_b = uniform(rng, bounds);
auto max_b = uniform(rng, tg::aabb3(min_b, bounds.max));
// generate one separating axis
auto const dim = tg::uniform(rng, {0, 1, 2});
auto const dir = tg::uniform(rng, {true, false});
auto const dim = uniform(rng, {0, 1, 2});
auto const dir = uniform(rng, {true, false});
if (dir)
{
min_b[dim] = tg::uniform(rng, max_a[dim], bounds.max[dim]);
max_b[dim] = tg::uniform(rng, min_b[dim], bounds.max[dim]);
min_b[dim] = uniform(rng, max_a[dim], bounds.max[dim]);
max_b[dim] = uniform(rng, min_b[dim], bounds.max[dim]);
}
else
{
max_b[dim] = tg::uniform(rng, bounds.min[dim], min_a[dim]);
min_b[dim] = tg::uniform(rng, bounds.min[dim], max_b[dim]);
max_b[dim] = uniform(rng, bounds.min[dim], min_a[dim]);
min_b[dim] = uniform(rng, bounds.min[dim], max_b[dim]);
}
auto const aabb_b = tg::aabb3(min_b, max_b);
@@ -73,3 +64,66 @@ TG_FUZZ_TEST(AABB, NonIntersect)
CHECK(!tg::intersects(aabb_a, aabb_b));
}
}
TG_FUZZ_TEST(AABB, SamplingTest)
{
auto const bounds = tg::aabb3(-10, 10);
{
auto const min_a = uniform(rng, bounds);
auto const max_a = uniform(rng, tg::aabb3(min_a, bounds.max));
auto const min_b = uniform(rng, bounds);
auto const max_b = uniform(rng, tg::aabb3(min_b, bounds.max));
auto const aabb_a = tg::aabb3(min_a, max_a);
auto const aabb_b = tg::aabb3(min_b, max_b);
auto const res = intersection(aabb_a, aabb_b);
if (res.has_value())
{
auto const intsct = res.value();
for (auto i = 0; i < 100; ++i)
{
auto const v = uniform(rng, bounds);
if (contains(intsct, v))
{
CHECK(contains(aabb_a, v));
CHECK(contains(aabb_b, v));
}
if (contains(aabb_a, v) && contains(aabb_b, v))
{
CHECK(contains(intsct, v));
}
if (!contains(aabb_a, v))
{
CHECK(!contains(intsct, v));
}
if (!contains(aabb_b, v))
{
CHECK(!contains(intsct, v));
}
}
}
else
{
// no intersection
for (auto i = 0; i < 50; ++i)
{
auto const v = uniform(rng, aabb_a);
CHECK(!contains(aabb_b, v));
}
for (auto i = 0; i < 50; ++i)
{
auto const v = uniform(rng, aabb_b);
CHECK(!contains(aabb_a, v));
}
}
}
}
Loading