Line data Source code
1 : /** 2 : * @file test_BoundingBox.cpp 3 : * 4 : * @brief Test for BoundingBox struct 5 : * 6 : * @author David Frank - initial code 7 : */ 8 : 9 : #include "doctest/doctest.h" 10 : #include "BoundingBox.h" 11 : #include "testHelpers.h" 12 : 13 : using namespace elsa; 14 : using namespace doctest; 15 : 16 : TEST_CASE("BoundingBox: Testing 2D AABB") 17 2 : { 18 2 : GIVEN("An aabb of size 10x15") 19 2 : { 20 : // setup 21 2 : std::size_t dim = 2; 22 2 : index_t x = 10; 23 2 : index_t y = 15; 24 2 : IndexVector_t volumeDims(dim); 25 2 : volumeDims << x, y; 26 : 27 2 : WHEN("instantiating the AABB") 28 2 : { 29 1 : BoundingBox aabb(volumeDims); 30 : 31 1 : THEN("The min is set to the origin (0, 0) and the max is (10, 15)") 32 1 : { 33 1 : REQUIRE_EQ(aabb.dim(), dim); 34 : 35 1 : REQUIRE_UNARY(checkApproxEq(aabb.min()(0), 0)); 36 1 : REQUIRE_UNARY(checkApproxEq(aabb.min()(1), 0)); 37 : 38 1 : REQUIRE_UNARY(checkApproxEq(aabb.max()(0), (real_t) x)); 39 1 : REQUIRE_UNARY(checkApproxEq(aabb.max()(1), (real_t) y)); 40 1 : } 41 1 : } 42 : 43 2 : WHEN("copying the AABB") 44 2 : { 45 1 : BoundingBox aabb(volumeDims); 46 1 : auto aabbcopy = aabb; 47 : 48 1 : THEN("A copy is created successfully") 49 1 : { 50 1 : REQUIRE_EQ(aabbcopy.dim(), dim); 51 : 52 1 : REQUIRE_UNARY(checkApproxEq(aabbcopy.min()(0), 0)); 53 1 : REQUIRE_UNARY(checkApproxEq(aabbcopy.min()(1), 0)); 54 : 55 1 : REQUIRE_UNARY(checkApproxEq(aabbcopy.max()(0), (real_t) x)); 56 1 : REQUIRE_UNARY(checkApproxEq(aabbcopy.max()(1), (real_t) y)); 57 1 : } 58 1 : } 59 2 : } 60 2 : } 61 : 62 : TEST_CASE("BoundingBox: Testing 3D aabb") 63 1 : { 64 1 : GIVEN("An aabb of size 10x15x20 with uniform") 65 1 : { 66 : // setup 67 1 : size_t dim = 3; 68 1 : index_t x = 10; 69 1 : index_t y = 15; 70 1 : index_t z = 20; 71 1 : IndexVector_t volumeDims(dim); 72 1 : volumeDims << x, y, z; 73 : 74 1 : WHEN("instantiating the AABB") 75 1 : { 76 1 : BoundingBox aabb(volumeDims); 77 : 78 1 : THEN("The min is set to the origin (0, 0, 0) and the max is (10, 15, 20)") 79 1 : { 80 1 : REQUIRE_EQ(aabb.dim(), dim); 81 : 82 1 : REQUIRE_UNARY(checkApproxEq(aabb.min()(0), 0)); 83 1 : REQUIRE_UNARY(checkApproxEq(aabb.min()(1), 0)); 84 1 : REQUIRE_UNARY(checkApproxEq(aabb.min()(2), 0)); 85 : 86 1 : REQUIRE_UNARY(checkApproxEq(aabb.max()(0), (real_t) x)); 87 1 : REQUIRE_UNARY(checkApproxEq(aabb.max()(1), (real_t) y)); 88 1 : REQUIRE_UNARY(checkApproxEq(aabb.max()(2), (real_t) z)); 89 1 : } 90 1 : } 91 1 : } 92 1 : }