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**)
|
|
|
|
{
|
2015-04-13 16:45:56 +10:00
|
|
|
util::TAP::logger tap;
|
2018-05-03 17:33:42 +10:00
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
util::point2f lo;
|
|
|
|
util::point2f hi;
|
|
|
|
|
|
|
|
util::point2f base;
|
|
|
|
util::vector2f direction;
|
|
|
|
|
|
|
|
float distance;
|
|
|
|
|
|
|
|
const char *message;
|
|
|
|
} const TESTS[] {
|
|
|
|
{
|
|
|
|
{ 1, 1 }, { 9, 9 },
|
|
|
|
{ 2, 2 }, { 1/std::sqrt (2.f), 1/std::sqrt (2.f) },
|
|
|
|
std::sqrt (7.f * 7 * 2),
|
|
|
|
"ray doesn't give negative distance to closest edge"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (auto const &t: TESTS) {
|
|
|
|
util::geom::aabb2f const shape (t.lo, t.hi);
|
|
|
|
util::geom::ray2f const r {t.base, t.direction};
|
|
|
|
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
|
|
|
}
|