5
5
6
6
#include < tev/Common.h>
7
7
8
-
9
8
namespace tev {
10
9
11
10
template <typename T, uint32_t N_DIMS>
@@ -20,8 +19,15 @@ struct Box {
20
19
template <typename U>
21
20
Box (const Box<U, N_DIMS>& other) : min{other.min }, max{other.max } {}
22
21
22
+ Box (const std::vector<Vector>& points) : Box() {
23
+ for (const auto & point : points) {
24
+ min = nanogui::min (min, point);
25
+ max = nanogui::max (max, point);
26
+ }
27
+ }
28
+
23
29
Vector size () const {
24
- return max - min;
30
+ return nanogui:: max(max - min, Vector{(T) 0 }) ;
25
31
}
26
32
27
33
Vector middle () const {
@@ -44,6 +50,26 @@ struct Box {
44
50
return result;
45
51
}
46
52
53
+ bool contains_inclusive (const Vector& pos) const {
54
+ bool result = true ;
55
+ for (uint32_t i = 0 ; i < N_DIMS; ++i) {
56
+ result &= pos[i] >= min[i] && pos[i] <= max[i];
57
+ }
58
+ return result;
59
+ }
60
+
61
+ bool contains (const Box& other) const {
62
+ return contains_inclusive (other.min ) && contains_inclusive (other.max );
63
+ }
64
+
65
+ Box intersect (const Box& other) const {
66
+ return {nanogui::max (min, other.min ), nanogui::min (max, other.max )};
67
+ }
68
+
69
+ Box translate (const Vector& offset) const {
70
+ return {min + offset, max + offset};
71
+ }
72
+
47
73
bool operator ==(const Box& other) const {
48
74
return min == other.min && max == other.max ;
49
75
}
@@ -55,6 +81,12 @@ struct Box {
55
81
Vector min, max;
56
82
};
57
83
84
+ template <typename Stream, typename T, uint32_t N_DIMS, std::enable_if_t <std::is_base_of_v<std::ostream, Stream>, int > = 0 >
85
+ Stream& operator <<(Stream& os, const Box<T, N_DIMS>& v) {
86
+ os << ' [' << v.min << " , " << v.max << ' ]' ;
87
+ return os;
88
+ }
89
+
58
90
using Box2f = Box<float , 2 >;
59
91
using Box3f = Box<float , 3 >;
60
92
using Box4f = Box<float , 4 >;
0 commit comments