diff --git a/test/geom/aabb.cpp b/test/geom/aabb.cpp index 177d0553..23571147 100644 --- a/test/geom/aabb.cpp +++ b/test/geom/aabb.cpp @@ -1,15 +1,45 @@ #include "geom/aabb.hpp" +#include "geom/ray.hpp" #include "tap.hpp" #include -using util::geom::aabb2f; - int main (int, char**) { util::TAP::logger tap; + + { + + + 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); + } + }; + + return tap.status (); }