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