2015-10-13 18:19:47 +11:00
|
|
|
#include "geom/aabb.hpp"
|
2018-05-03 17:33:42 +10:00
|
|
|
#include "geom/ray.hpp"
|
2015-04-09 14:05:01 +10:00
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
#include "tap.hpp"
|
|
|
|
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
|
2015-04-09 14:05:01 +10:00
|
|
|
int
|
|
|
|
main (int, char**)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2018-05-03 17:33:42 +10:00
|
|
|
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
const auto upright = normalised (cruft::vector2f {1});
|
2018-05-03 17:33:42 +10:00
|
|
|
|
|
|
|
static struct {
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::point2f lo;
|
|
|
|
cruft::point2f hi;
|
2018-05-03 17:33:42 +10:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::point2f base;
|
|
|
|
cruft::vector2f direction;
|
2018-05-03 17:33:42 +10:00
|
|
|
|
|
|
|
float distance;
|
|
|
|
|
|
|
|
const char *message;
|
|
|
|
} const TESTS[] {
|
2018-05-04 17:06:32 +10:00
|
|
|
{
|
|
|
|
{ 0, 0 }, { 1, 1 },
|
|
|
|
{ 0, 0 }, upright,
|
|
|
|
std::sqrt (2.f),
|
|
|
|
"ray on aabb corner, pointing to opposite corner",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{ 0, 0 }, { 1, 1 },
|
|
|
|
{ 0, 1 }, upright,
|
|
|
|
INFINITY,
|
|
|
|
"ray on aabb implied corner, pointing away",
|
|
|
|
},
|
2018-05-03 17:33:42 +10:00
|
|
|
{
|
|
|
|
{ 1, 1 }, { 9, 9 },
|
2018-05-04 17:06:32 +10:00
|
|
|
{ 2, 2 }, upright,
|
2018-05-03 17:33:42 +10:00
|
|
|
std::sqrt (7.f * 7 * 2),
|
2018-05-04 17:06:32 +10:00
|
|
|
"ray inside aabb, close to one corner and pointing to far corner",
|
|
|
|
},
|
2018-05-03 17:33:42 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto const &t: TESTS) {
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::geom::aabb2f const shape (t.lo, t.hi);
|
|
|
|
cruft::geom::ray2f const r {t.base, t.direction};
|
2018-05-03 17:33:42 +10:00
|
|
|
tap.expect_eq (distance (r, shape), t.distance, "%!", t.message);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-22 13:55:21 +10:00
|
|
|
return tap.status ();
|
2015-04-09 14:05:01 +10:00
|
|
|
}
|