Skip to content

Commit 21851da

Browse files
committed
- Add bbox expand & contains
- Catch errors only on release mode, not on DEBUG
1 parent 87c9aae commit 21851da

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

rawrbox.engine/src/engine.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ namespace rawrbox {
5959

6060
// Setup render threading
6161
auto renderThread = std::jthread([this]() {
62+
#ifndef _DEBUG
6263
try {
64+
#endif
6365
rawrbox::RENDER_THREAD_ID = std::this_thread::get_id();
6466
rawrbox::ThreadUtils::setName("rawrbox:render");
6567

@@ -113,6 +115,7 @@ namespace rawrbox {
113115

114116
this->onThreadShutdown(rawrbox::ENGINE_THREADS::THREAD_RENDER);
115117
this->_shutdown = rawrbox::ENGINE_THREADS::THREAD_INPUT; // Done killing rendering, now destroy glfw
118+
#ifndef _DEBUG
116119
} catch (const cpptrace::exception_with_message& err) {
117120
this->prettyPrintErr(err.message());
118121

@@ -125,6 +128,7 @@ namespace rawrbox {
125128
cpptrace::generate_trace().print();
126129
throw err;
127130
}
131+
#endif
128132
});
129133
// ----
130134

rawrbox.math/include/rawrbox/math/bbox.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,22 @@ namespace rawrbox {
2525
return this->_size;
2626
}
2727

28+
void expand(const rawrbox::Vector3_t<NumberType>& pos) {
29+
if (pos.x < _min.x) _min.x = pos.x;
30+
if (pos.y < _min.y) _min.y = pos.y;
31+
if (pos.z < _min.z) _min.z = pos.z;
32+
33+
if (pos.x > _max.x) _max.x = pos.x;
34+
if (pos.y > _max.y) _max.y = pos.y;
35+
if (pos.z > _max.z) _max.z = pos.z;
36+
37+
_size = _max - _min;
38+
}
39+
40+
bool contains(const rawrbox::Vector3_t<NumberType>& pos) {
41+
return pos.x >= _min.x && pos.x <= _max.x && pos.y >= _min.y && pos.y <= _max.y && pos.z >= _min.z && pos.z <= _max.z;
42+
}
43+
2844
void combine(const BBOX_t<NumberType>& b) {
2945
this->_min = {std::min(this->_min.x, b._min.x), std::min(this->_min.y, b._min.y), std::min(this->_min.z, b._min.z)};
3046
this->_max = {std::max(this->_max.x, b._max.x), std::max(this->_max.y, b._max.y), std::max(this->_max.z, b._max.z)};

rawrbox.math/tests/bbox.spec.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)