geom/ellipse: add ray distance tests

This commit is contained in:
Danny Robson 2018-04-16 15:59:39 +10:00
parent 1889a76e26
commit f21297cad5
2 changed files with 42 additions and 1 deletions

View File

@ -492,8 +492,9 @@ if (TESTS)
float
format
geom/aabb
geom/ray
geom/ellipse
geom/frustum
geom/ray
geom/sphere
hash/checksum
hash/crc

40
test/geom/ellipse.cpp Normal file
View File

@ -0,0 +1,40 @@
#include "tap.hpp"
#include "geom/ellipse.hpp"
#include "geom/ray.hpp"
#include "point.hpp"
#include "vector.hpp"
int
main ()
{
util::TAP::logger tap;
static struct {
util::geom::ellipse3f shape;
util::geom::ray3f caster;
float distance;
const char *message;
} const TESTS[] = {
{
.shape = { .origin = {0}, .radius = {1}, .up = {0,1,0} },
.caster = { .origin = { 0, 0, -2 }, .direction = util::vector3f{ 0, 0, 1 } },
.distance = 1,
.message = "sphere on origin, ray mostly on origin"
},
{
.shape = { .origin = {0}, .radius = {1,1,1.5}, .up = {0,1,0} },
.caster = { .origin = {0,0,-2}, .direction = util::vector3f{0,0,1} },
.distance = .5f,
.message = "ellipse on origin, extended on z, ray along z",
},
};
for (auto const& t: TESTS) {
tap.expect_eq (t.distance, distance (t.caster, t.shape), "%s", t.message);
}
return tap.status ();
}