libcruft-util/test/geom/plane.cpp

36 lines
892 B
C++
Raw Normal View History

2018-04-20 15:07:49 +10:00
#include "geom/plane.hpp"
#include "point.hpp"
#include "tap.hpp"
void
test_distances (cruft::TAP::logger &tap)
2018-04-20 15:07:49 +10:00
{
static struct {
cruft::point3f a, b, c;
cruft::point3f query;
2018-04-20 15:07:49 +10:00
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 = cruft::geom::make_plane (t.a, t.b, t.c);
2018-04-20 15:07:49 +10:00
const auto d = distance (p, t.query);
tap.expect_eq (d, t.distance, "%!", t.message);
}
};
int
main (int, char**)
{
cruft::TAP::logger tap;
2018-04-20 15:07:49 +10:00
test_distances (tap);
return tap.status ();
}