diff --git a/test/geom/plane.cpp b/test/geom/plane.cpp new file mode 100644 index 00000000..5f2d23fe --- /dev/null +++ b/test/geom/plane.cpp @@ -0,0 +1,36 @@ +#include "geom/plane.hpp" +#include "point.hpp" +#include "tap.hpp" + + +void +test_distances (util::TAP::logger &tap) +{ + static struct { + util::point3f a, b, c; + util::point3f query; + float distance; + const char *message; + } const TESTS[] = { + { { 0, 0, 0 }, { 0, 1, 0 }, { 1, 0, 0 }, { 0, 0, 0 }, 0, "colinear with plane about -z" }, + { { 0, 0, 0 }, { 0, 1, 0 }, { 1, 0, 0 }, { 0, 0,-1 }, 1, "in front of plane about -z" }, + { { 0, 0, 0 }, { 0, 1, 0 }, { 1, 0, 0 }, { 0, 0, 1 }, -1, "behind plane about -z" }, + }; + + for (auto const &t: TESTS) { + auto const p = util::geom::make_plane (t.a, t.b, t.c); + const auto d = distance (p, t.query); + tap.expect_eq (d, t.distance, "%!", t.message); + } +}; + + +int +main (int, char**) +{ + util::TAP::logger tap; + + test_distances (tap); + + return tap.status (); +} \ No newline at end of file