2018-04-13 18:46:37 +10:00
|
|
|
#include "tap.hpp"
|
|
|
|
|
|
|
|
#include "geom/sphere.hpp"
|
|
|
|
|
|
|
|
using util::geom::ray2f;
|
|
|
|
using util::geom::ray3f;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
void
|
|
|
|
test_intersect (util::TAP::logger &tap)
|
|
|
|
{
|
|
|
|
using util::geom::sphere3f;
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
float d;
|
|
|
|
sphere3f s;
|
|
|
|
ray3f r;
|
|
|
|
const char *message;
|
|
|
|
} TESTS[] = {
|
|
|
|
{
|
|
|
|
1.f,
|
|
|
|
{ util::point3f {0.f}, 1.f },
|
|
|
|
{ util::point3f {0, 2, 0}, util::vector3f {0,-1,0} },
|
|
|
|
"straight towards unit-origin sphere"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
0.f,
|
|
|
|
{ util::point3f {0}, 1.f },
|
|
|
|
{ util::point3f {0,1,0}, util::vector3f {0,1,0} },
|
|
|
|
"ray origin coincides with unit-origin sphere",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
INFINITY,
|
|
|
|
{ util::point3f {0}, 1 },
|
|
|
|
{ util::point3f {0,2,0}, util::vector3f {0,1,0} },
|
|
|
|
"offset ray never intersects unit-origin sphere"
|
2018-04-16 15:59:16 +10:00
|
|
|
},
|
|
|
|
{
|
|
|
|
1.f,
|
|
|
|
{ util::point3f {1,1,1}, 1 },
|
|
|
|
{ util::point3f {2,2,1}, util::vector3f{-1,0,0} },
|
|
|
|
"glancing ray at unit distance"
|
2018-04-13 18:46:37 +10:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto &[d,s,r,msg]: TESTS) {
|
|
|
|
tap.expect_eq (d, distance (r, s), "%!", msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int
|
|
|
|
main ()
|
|
|
|
{
|
|
|
|
util::TAP::logger tap;
|
|
|
|
test_intersect (tap);
|
|
|
|
return tap.status ();
|
|
|
|
}
|