preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BoundingBoxTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <algorithm>
3#include <vector>
4#include "logging/Logger.hpp"
6#include "mesh/Vertex.hpp"
8#include "testing/Testing.hpp"
9
10using namespace precice;
11using namespace precice::mesh;
12
13BOOST_AUTO_TEST_SUITE(MeshTests)
14BOOST_AUTO_TEST_SUITE(BoundingBoxTests)
15
18{
20 { // 3D
21 Eigen::VectorXd boundMin(3);
22 boundMin << 1.0, 2.0, 3.0;
23 Eigen::VectorXd boundMax(3);
24 boundMax << 4.0, 5.0, 6.0;
25 BoundingBox bb(boundMin, boundMax);
26
27 BOOST_TEST(bb.getDimension() == 3);
28 BOOST_TEST(bb.minCorner() == boundMin);
29 BOOST_TEST(bb.maxCorner() == boundMax);
30 }
31 { // 2D
32 Eigen::VectorXd boundMin(2);
33 boundMin << 1.0, 2.0;
34 Eigen::VectorXd boundMax(2);
35 boundMax << 4.0, 5.0;
36 BoundingBox bb(boundMin, boundMax);
37
38 BOOST_TEST(bb.getDimension() == 2);
39 BOOST_TEST(bb.minCorner() == boundMin);
40 BOOST_TEST(bb.maxCorner() == boundMax);
41 }
42} // Constructor
43
45BOOST_AUTO_TEST_CASE(ExpandByBoundingBox)
46{
48 { // 3D
49 BoundingBox bb1({0.0, 1.0,
50 0.0, 1.0,
51 0.0, 1.0});
52 BoundingBox bb2({-1.0, 0.5,
53 2.0, 3.5,
54 0.0, 4.0});
55 bb1.expandBy(bb2);
56 std::vector<double> compareData = {-1.0, 1.0,
57 0.0, 3.5,
58 0.0, 4.0};
59 BOOST_TEST(bb1.dataVector() == compareData);
60 }
61 { // 2D
62 BoundingBox bb1({0.0, 2.0,
63 -1.0, 1.0});
64 BoundingBox bb2({-1.0, 0.5,
65 2.0, 3.5});
66 bb1.expandBy(bb2);
67 std::vector<double> compareData = {-1.0, 2.0,
68 -1.0, 3.5};
69 BOOST_TEST(bb1.dataVector() == compareData);
70 }
71} // ExpandByBoundingBox
72
74BOOST_AUTO_TEST_CASE(ExpandByVertex)
75{
77 { // 3D
78 BoundingBox bb({0.0, 1.0,
79 0.0, 1.0,
80 0.0, 1.0});
81 Vertex v1(Eigen::Vector3d(-1.0, 3.0, 0.5), 0);
82 bb.expandBy(v1);
83 std::vector<double> compareData = {-1.0, 1.0,
84 0.0, 3.0,
85 0.0, 1.0};
86 BOOST_TEST(bb.dataVector() == compareData);
87 }
88 { // 2D
89 BoundingBox bb({-2.0, 1.0,
90 2.0, 4.0});
91 Vertex v1(Eigen::Vector2d(-4.0, 2.0), 0);
92 bb.expandBy(v1);
93 std::vector<double> compareData = {-4.0, 1.0,
94 2.0, 4.0};
95 BOOST_TEST(bb.dataVector() == compareData);
96 }
97} // ExpandByVertex
98
100BOOST_AUTO_TEST_CASE(ExpandByRadius)
101{
102 PRECICE_TEST();
103 { // 3D
104 BoundingBox bb({0.0, 1.0,
105 0.5, 2.0,
106 -1.0, 3.0});
107 double supportRadius = 1.0;
108 bb.expandBy(supportRadius);
109 std::vector<double> compareData = {-1.0, 2.0,
110 -0.5, 3.0,
111 -2.0, 4.0};
112 BOOST_TEST(bb.dataVector() == compareData);
113 }
114 { // 2D
115 BoundingBox bb({-2.0, 1.0,
116 0.5, 2.0});
117 double supportRadius = 1.0;
118 bb.expandBy(supportRadius);
119 std::vector<double> compareData = {-3.0, 2.0,
120 -0.5, 3.0};
121 BOOST_TEST(bb.dataVector() == compareData);
122 }
123} // ExpandByRadius
124
125PRECICE_TEST_SETUP(1_rank)
127{
128 PRECICE_TEST();
129 { // 3D
130 BoundingBox bb1({-1.0, 1.0,
131 0.5, 2.0,
132 1.0, 1.5});
133 double safetyFactor = 2.0;
134 bb1.scaleBy(safetyFactor);
135 std::vector<double> compareData = {-5.0, 5.0,
136 -3.5, 6.0,
137 -3.0, 5.5};
138 BOOST_TEST(bb1.dataVector() == compareData);
139 }
140 { // 2D
141 BoundingBox bb1({-1.0, 1.0,
142 0.5, 2.0});
143 double safetyFactor = 2.0;
144 bb1.scaleBy(safetyFactor);
145 std::vector<double> compareData = {-5.0, 5.0,
146 -3.5, 6.0};
147 BOOST_TEST(bb1.dataVector() == compareData);
148 }
149} // Scaling
150
151PRECICE_TEST_SETUP(1_rank)
152BOOST_AUTO_TEST_CASE(CenterOfGravity)
153{
154 PRECICE_TEST();
155 { // 3D
156 BoundingBox bb({0.0, 1.0,
157 -1.0, 3.0,
158 2.0, 4.0});
159
160 Eigen::Vector3d compareCOG(0.5, 1.0, 3.0);
161 BOOST_TEST(compareCOG == bb.center());
162 }
163 { // 2D
164 BoundingBox bb({0.0, 1.0,
165 -2.0, 5.0});
166
167 Eigen::Vector2d compareCOG(0.5, 1.5);
168 BOOST_TEST(compareCOG == bb.center());
169 }
170} // CenterOfGravity
171
172PRECICE_TEST_SETUP(1_rank)
174{
175 PRECICE_TEST();
176 { // 3D
177 BoundingBox bb({0.0, 1.0,
178 -1.0, 3.0,
179 2.0, 4.0});
180
181 Eigen::Vector3d compareMin(0.0, -1.0, 2.0);
182 Eigen::Vector3d compareMax(1.0, 3.0, 4.0);
183 BOOST_TEST(compareMin == bb.minCorner());
184 BOOST_TEST(compareMax == bb.maxCorner());
185 }
186 { // 2D
187 BoundingBox bb({-1.0, 3.0,
188 2.0, 4.0});
189
190 Eigen::Vector2d compareMin(-1.0, 2.0);
191 Eigen::Vector2d compareMax(3.0, 4.0);
192 BOOST_TEST(compareMin == bb.minCorner());
193 BOOST_TEST(compareMax == bb.maxCorner());
194 }
195} // CenterOfGravity
196
197PRECICE_TEST_SETUP(1_rank)
199{
200 PRECICE_TEST();
201 { // 3D
202 BoundingBox bb({0.0, 1.0,
203 -1.0, 3.0,
204 2.0, 4.0});
205
206 BOOST_TEST(bb.getEdgeLength(0) == 1.0);
207 BOOST_TEST(bb.getEdgeLength(1) == 4.0);
208 BOOST_TEST(bb.getEdgeLength(2) == 2.0);
209
210 BOOST_TEST(bb.longestEdgeLength() == 4.0);
211 }
212 { // 2D
213 BoundingBox bb({-1.0, 3.0,
214 2.0, 4.0});
215
216 BOOST_TEST(bb.getEdgeLength(0) == 4.0);
217 BOOST_TEST(bb.getEdgeLength(1) == 2.0);
218
219 BOOST_TEST(bb.longestEdgeLength() == 4.0);
220 }
221}
222
223PRECICE_TEST_SETUP(1_rank)
225{
226 PRECICE_TEST();
227 { // 3D
228 BoundingBox bb({0.0, 1.0,
229 -1.0, 3.0,
230 2.0, 4.0});
231 {
232 std::vector<bool> deadAxis = {false, false, true};
233 double compareArea = 4.0;
234 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
235 }
236 {
237 std::vector<bool> deadAxis = {false, true, false};
238 double compareArea = 2.0;
239 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
240 }
241 {
242 std::vector<bool> deadAxis = {true, false, false};
243 double compareArea = 8.0;
244 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
245 }
246 {
247 std::vector<bool> deadAxis = {false, false, false};
248 double compareArea = 8.0;
249 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
250 }
251 }
252 { // 2D
253 BoundingBox bb({0.0, 1.0,
254 -1.0, 3.0});
255 {
256 std::vector<bool> deadAxis = {false, true};
257 double compareArea = 1.0;
258 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
259 }
260 {
261 std::vector<bool> deadAxis = {true, false};
262 double compareArea = 4.0;
263 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
264 }
265 {
266 std::vector<bool> deadAxis = {false, false};
267 double compareArea = 4.0;
268 BOOST_TEST(bb.getArea(deadAxis) == compareArea);
269 }
270 }
271} // Area
272
273PRECICE_TEST_SETUP(1_rank)
275{
276 PRECICE_TEST();
277 { // 3D
278 BoundingBox bb1({0.0, 1.0,
279 -1.0, 3.0,
280 2.0, 4.0});
281 BoundingBox bb2({-1.0, 0.5,
282 2.0, 5.0,
283 1.0, 3.0});
284 BoundingBox bb3({2.0, 5.0,
285 4.0, 5.0,
286 0.0, 1.0});
287
288 BOOST_TEST(bb1.overlapping(bb2));
289 BOOST_TEST(!bb1.overlapping(bb3));
290 }
291 { // 2D
292 BoundingBox bb1({0.0, 1.0,
293 -1.0, 3.0});
294 BoundingBox bb2({-1.0, 0.5,
295 2.0, 5.0});
296 BoundingBox bb3({2.0, 5.0,
297 4.0, 5.0});
298
299 BOOST_TEST(bb1.overlapping(bb2));
300 BOOST_TEST(!bb1.overlapping(bb3));
301 }
302} // Overalapping
303
304PRECICE_TEST_SETUP(1_rank)
306{
307 PRECICE_TEST();
308 { // 3D
309 BoundingBox bb1({0.0, 1.0,
310 -1.0, 3.0,
311 2.0, 4.0});
312 BoundingBox bb2({0.0, 1.0,
313 -1.0, 3.0,
314 2.0, 4.0});
315 BoundingBox bb3({2.0, 5.0,
316 4.0, 5.0,
317 0.0, 1.0});
318
319 BOOST_TEST(bb1 == bb2);
320 BOOST_TEST(!(bb1 == bb3));
321 }
322 { // 2D
323 BoundingBox bb1({0.0, 1.0,
324 -1.0, 3.0});
325 BoundingBox bb2({0.0, 1.0,
326 -1.0, 3.0});
327 BoundingBox bb3({2.0, 5.0,
328 4.0, 5.0});
329
330 BOOST_TEST(bb1 == bb2);
331 BOOST_TEST(!(bb1 == bb3));
332 }
333} // Comparison
334
335PRECICE_TEST_SETUP(1_rank)
337{
338 PRECICE_TEST();
339 { // 3D
340 BoundingBox bb({0.0, 1.0,
341 -1.0, 3.0,
342 2.0, 4.0});
343 Vertex v1(Eigen::Vector3d(0.2, 1.0, 3.0), 0);
344 Vertex v2(Eigen::Vector3d(1.2, -2.0, 5.0), 0);
345
346 BOOST_TEST(bb.contains(v1));
347 BOOST_TEST(!bb.contains(v2));
348 }
349 { // 2D
350 BoundingBox bb({0.0, 1.0,
351 -1.0, 3.0});
352 Vertex v1(Eigen::Vector2d(0.2, 1.0), 0);
353 Vertex v2(Eigen::Vector2d(1.2, -2.0), 0);
354
355 BOOST_TEST(bb.contains(v1));
356 BOOST_TEST(!bb.contains(v2));
357 }
358 { // 3D Point
359 BoundingBox bb({0.0, 0.0, 0.0, 0.0, 0.0, 0.0});
360 Vertex v1(Eigen::Vector3d(0.0, 0.0, 0.0), 0);
361 Vertex v2(Eigen::Vector3d(1.2, -2.0, 1.0), 0);
362
363 BOOST_TEST(bb.contains(v1));
364 BOOST_TEST(!bb.contains(v2));
365 }
366 { // 2D Point
367 BoundingBox bb({0.0, 0.0, 0.0, 0.0});
368 Vertex v1(Eigen::Vector2d(0.0, 0.0), 0);
369 Vertex v2(Eigen::Vector2d(1.2, -2.0), 0);
370
371 BOOST_TEST(bb.contains(v1));
372 BOOST_TEST(!bb.contains(v2));
373 }
374} // Contains
375
376PRECICE_TEST_SETUP(1_rank)
378{
379 PRECICE_TEST();
380 { // 3D
381 BoundingBox bb1({0.0, 1.0,
382 -1.0, 3.0,
383 2.0, 4.0});
384 BoundingBox bb2(3);
385
386 BOOST_TEST(!bb1.isDefault());
387 BOOST_TEST(bb2.isDefault());
388 }
389 { // 2D
390 BoundingBox bb1({0.0, 1.0,
391 -1.0, 3.0});
392 BoundingBox bb2(2);
393
394 BOOST_TEST(!bb1.isDefault());
395 BOOST_TEST(bb2.isDefault());
396 }
397} // DefaultCase
398
399PRECICE_TEST_SETUP(1_rank)
401{
402 PRECICE_TEST();
403 { // 3D
404 BoundingBox bb1({0.0, 1.0,
405 -1.0, 3.0,
406 2.0, 4.0});
407 BoundingBox bb2(3);
408 BoundingBox bb3({1.0, 1.0,
409 1.0, 1.0,
410 1.0, 1.0});
411 BOOST_TEST(!bb1.empty());
412 BOOST_TEST(bb2.empty());
413 BOOST_TEST(bb3.empty());
414 }
415 { // 2D
416 BoundingBox bb1({0.0, 1.0,
417 -1.0, 3.0});
418 BoundingBox bb2(2);
419 BoundingBox bb3({2.0, 2.0,
420 1.0, 1.0});
421 BOOST_TEST(!bb1.empty());
422 BOOST_TEST(bb2.empty());
423 BOOST_TEST(bb3.empty());
424 }
425} // EmptyCase
426
427BOOST_AUTO_TEST_SUITE_END() // BoundingBox
BOOST_AUTO_TEST_CASE(Constructor)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST()
Definition Testing.hpp:39
#define PRECICE_TEST_SETUP(...)
Creates and attaches a TestSetup to a Boost test case.
Definition Testing.hpp:29
An axis-aligned bounding box around a (partition of a) mesh.
Eigen::VectorXd maxCorner() const
the max corner of the bounding box
Eigen::VectorXd minCorner() const
the min corner of the bounding box
void expandBy(const BoundingBox &otherBB)
Expand bounding box using another bounding box.
int getDimension() const
Getter dimension of the bounding box.
void scaleBy(double safetyFactor)
Increase the size of bounding box by safety margin.
Vertex of a mesh.
Definition Vertex.hpp:16
provides Mesh, Data and primitives.
Main namespace of the precice library.