-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaabb.h
More file actions
87 lines (71 loc) · 2.18 KB
/
aabb.h
File metadata and controls
87 lines (71 loc) · 2.18 KB
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
/*
* This file is part of the GreasePad distribution (https://github.com/FraunhoferIOSB/GreasePad).
* Copyright (c) 2022-2026 Jochen Meidow, Fraunhofer IOSB
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef AABB_H
#define AABB_H
#include <cassert>
#include <Eigen/Core>
namespace Geometry {
using Eigen::Vector;
//! Axis-aligned bounding box
template <typename T, int N>
class Aabb
{
public:
//! Value constructor
explicit Aabb( const Vector<T,N> & min, const Vector<T,N> & max)
: m_min(min), m_max(max)
{
assert( ( m_min.array() <= m_max.array() ).all() );
}
Aabb()
{
m_min.setZero();
m_max.setZero();
};
//! Get i-th minimum value
[[nodiscard]] T min( const int idx) const {
assert( idx>=0 && idx<N );
return m_min(idx);
}
//! Get i-th maximum value
[[nodiscard]] T max( const int idx) const {
assert( idx>=0 && idx<N );
return m_max(idx);
}
//! Check if the other box overlaps
[[nodiscard]] bool overlaps( const Aabb & other) const
{
return ( m_max.cwiseMin(other.m_max).array()
> m_min.cwiseMax(other.m_min).array() ).all();
}
//! Get united/merged box of this and the other box
[[nodiscard]] Aabb united( const Aabb & other) const
{
return Aabb {
m_min.cwiseMin(other.m_min),
m_max.cwiseMax(other.m_max)
};
}
//! Get dimension of bounding box
[[nodiscard]] int dim() const {return N;}
private:
Vector<T,N> m_min;
Vector<T,N> m_max;
};
} // namespace Geometry
#endif // AABB_H