|
| 1 | +#include <rawrbox/math/bbox.hpp> |
| 2 | + |
| 3 | +#include <catch2/catch_test_macros.hpp> |
| 4 | +#include <catch2/matchers/catch_matchers.hpp> |
| 5 | +#include <catch2/matchers/catch_matchers_floating_point.hpp> |
| 6 | + |
| 7 | +TEST_CASE("BBOX should behave as expected", "[rawrbox::BBOX]") { |
| 8 | + SECTION("rawrbox::BBOX") { |
| 9 | + rawrbox::BBOX bbox(rawrbox::Vector3f(0, 0, 0), rawrbox::Vector3f(1, 1, 1), rawrbox::Vector3f(1, 1, 1)); |
| 10 | + |
| 11 | + REQUIRE(bbox._min == rawrbox::Vector3f(0, 0, 0)); |
| 12 | + REQUIRE(bbox._max == rawrbox::Vector3f(1, 1, 1)); |
| 13 | + REQUIRE(bbox._size == rawrbox::Vector3f(1, 1, 1)); |
| 14 | + } |
| 15 | + |
| 16 | + SECTION("rawrbox::BBOX::isEmpty") { |
| 17 | + rawrbox::BBOX bbox1; |
| 18 | + rawrbox::BBOX bbox2(rawrbox::Vector3f(0, 0, 0), rawrbox::Vector3f(1, 1, 1), rawrbox::Vector3f(1, 1, 1)); |
| 19 | + |
| 20 | + REQUIRE(bbox1.isEmpty() == true); |
| 21 | + REQUIRE(bbox2.isEmpty() == false); |
| 22 | + } |
| 23 | + |
| 24 | + SECTION("rawrbox::BBOX::size") { |
| 25 | + rawrbox::BBOX bbox(rawrbox::Vector3f(0, 0, 0), rawrbox::Vector3f(1, 2, 3), rawrbox::Vector3f(1, 2, 3)); |
| 26 | + |
| 27 | + REQUIRE(bbox.size() == rawrbox::Vector3f(1, 2, 3)); |
| 28 | + } |
| 29 | + |
| 30 | + SECTION("rawrbox::BBOX::expand") { |
| 31 | + rawrbox::BBOX bbox(rawrbox::Vector3f(0, 0, 0), rawrbox::Vector3f(1, 1, 1), rawrbox::Vector3f(1, 1, 1)); |
| 32 | + bbox.expand(rawrbox::Vector3f(2, 2, 2)); |
| 33 | + |
| 34 | + REQUIRE(bbox._min == rawrbox::Vector3f(0, 0, 0)); |
| 35 | + REQUIRE(bbox._max == rawrbox::Vector3f(2, 2, 2)); |
| 36 | + REQUIRE(bbox._size == rawrbox::Vector3f(2, 2, 2)); |
| 37 | + } |
| 38 | + |
| 39 | + SECTION("rawrbox::BBOX::contains") { |
| 40 | + rawrbox::BBOX bbox(rawrbox::Vector3f(0, 0, 0), rawrbox::Vector3f(1, 1, 1), rawrbox::Vector3f(1, 1, 1)); |
| 41 | + |
| 42 | + REQUIRE(bbox.contains(rawrbox::Vector3f(0.5F, 0.5F, 0.5F)) == true); |
| 43 | + REQUIRE(bbox.contains(rawrbox::Vector3f(1.5F, 1.5F, 1.5F)) == false); |
| 44 | + } |
| 45 | + |
| 46 | + SECTION("rawrbox::BBOX::combine") { |
| 47 | + rawrbox::BBOX bbox1(rawrbox::Vector3f(0, 0, 0), rawrbox::Vector3f(1, 1, 1), rawrbox::Vector3f(1, 1, 1)); |
| 48 | + rawrbox::BBOX bbox2(rawrbox::Vector3f(1, 1, 1), rawrbox::Vector3f(2, 2, 2), rawrbox::Vector3f(1, 1, 1)); |
| 49 | + bbox1.combine(bbox2); |
| 50 | + |
| 51 | + REQUIRE(bbox1._min == rawrbox::Vector3f(0, 0, 0)); |
| 52 | + REQUIRE(bbox1._max == rawrbox::Vector3f(2, 2, 2)); |
| 53 | + } |
| 54 | + |
| 55 | + SECTION("rawrbox::BBOX::operators") { |
| 56 | + rawrbox::BBOX bbox1(rawrbox::Vector3f(0, 0, 0), rawrbox::Vector3f(1, 1, 1), rawrbox::Vector3f(1, 1, 1)); |
| 57 | + rawrbox::BBOX bbox2(rawrbox::Vector3f(0, 0, 0), rawrbox::Vector3f(1, 1, 1), rawrbox::Vector3f(1, 1, 1)); |
| 58 | + rawrbox::BBOX bbox3(rawrbox::Vector3f(0, 0, 0), rawrbox::Vector3f(2, 2, 2), rawrbox::Vector3f(2, 2, 2)); |
| 59 | + |
| 60 | + REQUIRE(bbox1 == bbox2); |
| 61 | + REQUIRE(bbox1 != bbox3); |
| 62 | + } |
| 63 | +} |
0 commit comments