2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/geom/aabb.hpp>
|
|
|
|
#include <cruft/util/geom/ray.hpp>
|
2015-04-09 14:05:01 +10:00
|
|
|
|
2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/tap.hpp>
|
2015-04-13 16:45:56 +10:00
|
|
|
|
|
|
|
#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};
|
2021-04-13 16:05:08 +10:00
|
|
|
tap.expect_eq (distance (r, shape), t.distance, "{}", t.message);
|
2018-05-03 17:33:42 +10:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-05-22 13:55:21 +10:00
|
|
|
return tap.status ();
|
2015-04-09 14:05:01 +10:00
|
|
|
}
|