libcruft-util/test/geom/sphere.cpp
Danny Robson f6056153e3 rename root namespace from util to cruft
This places, at long last, the core library code into the same namespace
as the extended library code.
2018-08-05 14:42:02 +10:00

60 lines
1.4 KiB
C++

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