1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// Copyright 2009 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
#include "../catch.hpp"
#include "rkcommon/math/box.h"
using namespace rkcommon::math;
#define RUN_FOR_ALL_TYPES(name) \
name<box2f>(); \
name<box3f>(); \
name<box3fa>(); \
name<box4f>(); \
name<box2i>(); \
name<box3i>(); \
name<box4i>();
template <typename T>
inline void test_area_2D()
{
using B = typename T::bound_t;
REQUIRE(area(T(B(1), B(2))) == 1);
}
TEST_CASE("2D box area function", "[box]")
{
test_area_2D<box2i>();
test_area_2D<box2f>();
}
template <typename T>
inline void test_area_3D()
{
using B = typename T::bound_t;
REQUIRE(area(T(B(1), B(2))) == 6);
}
TEST_CASE("3D box area function", "[box]")
{
test_area_3D<box3i>();
test_area_3D<box3f>();
test_area_3D<box3fa>();
}
template <typename T>
inline void test_volume()
{
using B = typename T::bound_t;
REQUIRE(volume(T(B(1), B(2))) == 1);
}
TEST_CASE("3D box volume function", "[box]")
{
test_volume<box3i>();
test_volume<box3f>();
test_volume<box3fa>();
}
template <typename T>
inline void test_touchingOrOverlapping()
{
using B = typename T::bound_t;
REQUIRE(touchingOrOverlapping(T(B(0), B(1)), T(B(2), B(3))) == false);
REQUIRE(touchingOrOverlapping(T(B(1), B(2)), T(B(2), B(3))) == true);
REQUIRE(touchingOrOverlapping(T(B(1), B(2)), T(B(1), B(2))) == true);
REQUIRE(touchingOrOverlapping(T(B(2), B(3)), T(B(1), B(2))) == true);
REQUIRE(touchingOrOverlapping(T(B(2), B(3)), T(B(0), B(1))) == false);
}
TEST_CASE("box touchingOrOverlapping function", "[box]")
{
test_touchingOrOverlapping<box2i>();
test_touchingOrOverlapping<box2f>();
test_touchingOrOverlapping<box3i>();
test_touchingOrOverlapping<box3f>();
test_touchingOrOverlapping<box3fa>();
}
template <typename T>
inline void test_intersectionOf()
{
using B = typename T::bound_t;
REQUIRE(intersectionOf(T(B(0), B(2)), T(B(1), B(3))) == T(B(1), B(2)));
}
TEST_CASE("box intersectionOf function", "[box]")
{
RUN_FOR_ALL_TYPES(test_intersectionOf);
}
template <typename T>
inline void test_disjoint()
{
using B = typename T::bound_t;
REQUIRE(disjoint(T(B(0), B(1)), T(B(2), B(3))) == true);
REQUIRE(disjoint(T(B(1), B(2)), T(B(2), B(3))) == false);
REQUIRE(disjoint(T(B(1), B(2)), T(B(1), B(2))) == false);
REQUIRE(disjoint(T(B(2), B(3)), T(B(1), B(2))) == false);
REQUIRE(disjoint(T(B(2), B(3)), T(B(0), B(1))) == true);
}
TEST_CASE("box disjoint function", "[box]")
{
RUN_FOR_ALL_TYPES(test_disjoint);
}
template <typename T>
inline void test_center()
{
using B = typename T::bound_t;
REQUIRE(center(T(B(0), B(2))) == B(1));
}
TEST_CASE("box center function", "[box]")
{
RUN_FOR_ALL_TYPES(test_center);
}
template <typename T>
inline bool CmpT(const T a, const T b, T epsilon = ulp)
{
return (abs(b - a) > epsilon) ? false : true;
}
template <typename T, int N>
inline void test_intersectRayBox()
{
using V = vec_t<T, N>;
using X = box_t<T, N>;
range_t<T> r = intersectRayBox(V(0), normalize(V(1)), X(V(1), V(2)));
// Tolerance 2x higher because of sse2neon
REQUIRE(abs(r.lower - length(V(1))) <= 2 * T(ulp));
REQUIRE(abs(r.upper - length(V(2))) <= 4 * T(ulp)); // rcp is multiplied by box.upper
}
TEST_CASE("box intersectRayBox function", "[box]")
{
test_intersectRayBox<float, 2>();
test_intersectRayBox<float, 3>();
test_intersectRayBox<double, 2>();
test_intersectRayBox<double, 3>();
}
|