aabb.cc 1.45 KB
Newer Older
1
2
3
4
#include "test.hh"

TG_FUZZ_TEST(TypedGeometry, AABB)
{
Philip Trettner's avatar
Philip Trettner committed
5
6
    auto p0 = uniform(rng, tg::aabb3(tg::pos3(-10.0f), tg::pos3(10.0f)));
    auto p1 = uniform(rng, tg::aabb3(tg::pos3(-10.0f), tg::pos3(10.0f)));
7

Philip Trettner's avatar
Philip Trettner committed
8
    auto b = aabb_of(p0, p1);
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

    CHECK(b.max.x >= p0.x);
    CHECK(b.max.y >= p0.y);
    CHECK(b.max.z >= p0.z);
    CHECK(b.max.x >= p1.x);
    CHECK(b.max.y >= p1.y);
    CHECK(b.max.z >= p1.z);

    CHECK(b.min.x <= p0.x);
    CHECK(b.min.y <= p0.y);
    CHECK(b.min.z <= p0.z);
    CHECK(b.min.x <= p1.x);
    CHECK(b.min.y <= p1.y);
    CHECK(b.min.z <= p1.z);
}
Philip Trettner's avatar
Philip Trettner committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

TG_FUZZ_TEST(TypedGeometry, ObjectAABB)
{
    auto bb2 = tg::aabb2(-10, 10);
    auto bb3 = tg::aabb3(-10, 10);

    auto test_obj = [&](auto obj) {
        auto bb = aabb_of(obj);
        auto p = uniform(rng, obj);
        CHECK(contains(bb, p));
    };

    // aabb
    test_obj(aabb_of(uniform(rng, bb2), uniform(rng, bb2)));
    test_obj(aabb_of(uniform(rng, bb3), uniform(rng, bb3)));

    // sphere
    test_obj(tg::sphere2(uniform(rng, bb2), uniform(rng, 0.5f, 3.0f)));
    test_obj(tg::sphere3(uniform(rng, bb3), uniform(rng, 0.5f, 3.0f)));

    // segment
    test_obj(tg::segment(uniform(rng, bb2), uniform(rng, bb2)));
    test_obj(tg::segment(uniform(rng, bb3), uniform(rng, bb3)));

    // triangle
    test_obj(tg::triangle(uniform(rng, bb2), uniform(rng, bb2), uniform(rng, bb2)));
    test_obj(tg::triangle(uniform(rng, bb3), uniform(rng, bb3), uniform(rng, bb3)));

    // TODO: more
}