geom/plane: add trivial plane tests

This commit is contained in:
Danny Robson 2018-04-20 15:07:49 +10:00
parent 08073b6ba1
commit 443112b33c

36
test/geom/plane.cpp Normal file
View File

@ -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 ();
}