7 #define BOOST_TEST_DYN_LINK
8 #include <boost/test/unit_test.hpp>
11 #include "Space/Shape/Box.hpp"
12 #include "Space/Ghost.hpp"
14 #define N_RANDOM_POINT 1024
16 BOOST_AUTO_TEST_SUITE( spacebox_test )
18 BOOST_AUTO_TEST_CASE( spacebox_use)
20 std::cout <<
"Box unit test start" <<
"\n";
24 float spacing[2] = {0.1,0.1};
30 BOOST_REQUIRE_CLOSE(sp.getLow(0),1.0,0.0001);
31 BOOST_REQUIRE_CLOSE(sp.getLow(1),1.0,0.0001);
32 BOOST_REQUIRE_CLOSE(sp.getHigh(0),1.1,0.0001);
33 BOOST_REQUIRE_CLOSE(sp.getHigh(1),1.1,0.0001);
43 BOOST_REQUIRE_CLOSE(sp.getLow(0),0.1,0.0001);
44 BOOST_REQUIRE_CLOSE(sp.getLow(1),0.1,0.0001);
45 BOOST_REQUIRE_CLOSE(sp.getHigh(0),0.3,0.0001);
46 BOOST_REQUIRE_CLOSE(sp.getHigh(1),0.3,0.0001);
58 BOOST_REQUIRE_EQUAL(inte,
true);
59 BOOST_REQUIRE_EQUAL(sp3.
getLow(0),1.0);
60 BOOST_REQUIRE_EQUAL(sp3.
getLow(1),1.0);
61 BOOST_REQUIRE_EQUAL(sp3.
getHigh(0),1.5);
62 BOOST_REQUIRE_EQUAL(sp3.
getHigh(1),1.5);
66 sp1.set({0.0,0.0},{1.0,1.0});
67 sp2.set({0.2,-0.5},{0.4,1.5});
69 inte = sp1.Intersect(sp2,sp3);
71 BOOST_REQUIRE_EQUAL(inte,
true);
72 BOOST_REQUIRE_EQUAL(sp3.
getLow(0),0.2f);
73 BOOST_REQUIRE_EQUAL(sp3.
getLow(1),0.0f);
74 BOOST_REQUIRE_EQUAL(sp3.
getHigh(0),0.4f);
75 BOOST_REQUIRE_EQUAL(sp3.
getHigh(1),1.0f);
77 sp1.set({0.0,0.0},{1.0,1.0});
78 sp2.set({0.2,0.2},{0.4,0.4});
80 inte = sp1.Intersect(sp2,sp3);
82 BOOST_REQUIRE_EQUAL(inte,
true);
83 BOOST_REQUIRE_EQUAL(sp3.
getLow(0),0.2f);
84 BOOST_REQUIRE_EQUAL(sp3.
getLow(1),0.2f);
85 BOOST_REQUIRE_EQUAL(sp3.
getHigh(0),0.4f);
86 BOOST_REQUIRE_EQUAL(sp3.
getHigh(1),0.4f);
88 sp1.set({0.0,0.0},{1.0,1.0});
89 sp2.set({1.2,0.0},{2.4,1.0});
91 inte = sp1.Intersect(sp2,sp3);
93 BOOST_REQUIRE_EQUAL(inte,
false);
98 sp1.set({0.0,0.0},{1.0,1.0});
99 sp2.set({0.5,0.1},{0.5,1.1});
101 inte = sp1.Intersect(sp2,sp3);
103 BOOST_REQUIRE_EQUAL(inte,
true);
104 BOOST_REQUIRE_EQUAL(sp3.
getLow(0),0.5f);
105 BOOST_REQUIRE_EQUAL(sp3.
getLow(1),0.1f);
106 BOOST_REQUIRE_EQUAL(sp3.
getHigh(0),0.5f);
107 BOOST_REQUIRE_EQUAL(sp3.
getHigh(1),1.0f);
111 sp1.set({0.0,0.0},{1.0,1.0});
112 sp2.set({1.0,0.0},{1.5,1.5});
114 inte = sp1.Intersect(sp2,sp3);
116 BOOST_REQUIRE_EQUAL(inte,
true);
117 BOOST_REQUIRE_EQUAL(sp3.
getLow(0),1.0f);
118 BOOST_REQUIRE_EQUAL(sp3.
getLow(1),0.0f);
119 BOOST_REQUIRE_EQUAL(sp3.
getHigh(0),1.0f);
120 BOOST_REQUIRE_EQUAL(sp3.
getHigh(1),1.0f);
123 sp1.set({0.0,0.0},{1.0,1.0});
128 BOOST_REQUIRE_EQUAL(sp1.getLow(0),-0.5f);
129 BOOST_REQUIRE_EQUAL(sp1.getLow(1),-0.5f);
130 BOOST_REQUIRE_EQUAL(sp1.getHigh(0),1.5f);
131 BOOST_REQUIRE_EQUAL(sp1.getHigh(1),1.5f);
138 for (
int i = 0 ; i < N_RANDOM_POINT ; i++)
142 BOOST_REQUIRE_EQUAL(sp_box.isInside(p),
true);
151 for (
int i = 0 ; i < N_RANDOM_POINT ; i++)
155 BOOST_REQUIRE_EQUAL(sp_box.isInside(p),
false);
158 std::cout <<
"Box unit test stop" <<
"\n";
162 BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
void mul(T(&sp)[dim])
multiply box p1,p2 points with the coefficients defined in sp
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
__device__ __host__ bool Intersect(const Box< dim, T > &b, Box< dim, T > &b_out) const
Intersect.
__device__ __host__ T getHigh(int i) const
get the high interval of the box
void rescale(T(&sp)[dim])
Re-scale box with the coefficient defined in sp.