libcruft-util/test/aabb.cpp

50 lines
938 B
C++
Raw Normal View History

2015-04-09 14:05:01 +10:00
#include "aabb.hpp"
2015-04-13 16:45:56 +10:00
#include "tap.hpp"
#include <tuple>
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
util::AABB2f box {
{ 2, 2 },
{ 8, 8 }
};
box.contract (2.f);
2015-04-13 16:45:56 +10:00
tap.expect_eq<util::AABB2f, util::AABB2f> (box, { { 3, 3 }, { 7, 7 }}, "over contraction");
2015-04-09 14:05:01 +10:00
}
{
// Test expansion
util::AABB2f box {
{ 2, 2 },
{ 8, 8 }
};
box.expand (2.f);
2015-04-13 18:06:08 +10:00
2015-04-13 16:45:56 +10:00
tap.expect_eq<util::AABB2f, util::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
util::AABB2f small {
{ 0, 0 },
{ 1, 1 }
};
small.contract (10);
2015-04-13 16:45:56 +10:00
tap.expect_eq<util::AABB2f, util::AABB2f> (small, { { 0.5f, 0.5f }, { 0.5f, 0.5f }}, "unsigned over-contract");
2015-04-09 14:05:01 +10:00
}
}