libcruft-util/test/geom/aabb.cpp

52 lines
916 B
C++
Raw Normal View History

#include "geom/aabb.hpp"
2015-04-09 14:05:01 +10:00
2015-04-13 16:45:56 +10:00
#include "tap.hpp"
#include <tuple>
using util::geom::AABB2f;
2015-04-13 16:45:56 +10:00
2015-04-09 14:05:01 +10:00
int
main (int, char**)
{
2015-04-13 16:45:56 +10:00
util::TAP::logger tap;
2015-04-09 14:05:01 +10:00
{
// Test contraction
AABB2f box {
2015-04-09 14:05:01 +10:00
{ 2, 2 },
{ 8, 8 }
};
box.contract (2.f);
tap.expect_eq<AABB2f, AABB2f> (box, { { 3, 3 }, { 7, 7 }}, "over contraction");
2015-04-09 14:05:01 +10:00
}
{
// Test expansion
AABB2f box {
2015-04-09 14:05:01 +10:00
{ 2, 2 },
{ 8, 8 }
};
box.expand (2.f);
2015-04-13 18:06:08 +10:00
tap.expect_eq<AABB2f, AABB2f> (box, { { 1, 1 }, { 9, 9 }}, "expansion");
2015-04-09 14:05:01 +10:00
}
{
// Ensure we don't wrap-around on unsigned position types when contracting
AABB2f small {
2015-04-09 14:05:01 +10:00
{ 0, 0 },
{ 1, 1 }
};
small.contract (10);
tap.expect_eq<AABB2f, AABB2f> (small, { { 0.5f, 0.5f }, { 0.5f, 0.5f }}, "unsigned over-contract");
2015-04-09 14:05:01 +10:00
}
}