AABox.hpp
Go to the documentation of this file.
1
2namespace GfxTL
3{
4 template <class Point>
5 AABox<Point>::AABox(const PointType& pmin, const PointType& pmax) : _pmin(pmin), _pmax(pmax)
6 {
7 }
8
9 template <class Point>
10 void
12 {
13 for (unsigned int i = 0; i < Dim; ++i)
14 {
15 _pmin[i] = -std::numeric_limits<ScalarType>::infinity();
16 _pmax[i] = std::numeric_limits<ScalarType>::infinity();
17 }
18 }
19
20 template <class Point>
21 void
22 AABox<Point>::Split(unsigned int axis,
23 ScalarType s,
24 AABox<Point>* left,
25 AABox<Point>* right) const
26 {
27 *left = *right = *this;
28 if (_pmax[axis] > s)
29 {
30 left->_pmax[axis] = s;
31 }
32 if (_pmin[axis] < s)
33 {
34 right->_pmin[axis] = s;
35 }
36 }
37
38 template <class Point>
39 void
41 {
42 *center = _pmin;
43 *center += _pmax;
44 *center /= 2;
45 }
46
47 template <class Point>
49 AABox<Point>::operator[](unsigned int index) const
50 {
52 for (unsigned int i = 0; i < Dim; ++i)
53 {
54 if (index & (1 << i))
55 {
56 p[i] = _pmin[i];
57 }
58 else
59 {
60 p[i] = _pmax[i];
61 }
62 }
63 return p;
64 }
65
66 template <class Point>
67 Point&
69 {
70 return _pmin;
71 }
72
73 template <class Point>
74 const Point&
76 {
77 return _pmin;
78 }
79
80 template <class Point>
81 Point&
83 {
84 return _pmax;
85 }
86
87 template <class Point>
88 const Point&
90 {
91 return _pmax;
92 }
93
94 template <class Point>
97 {
98 return (_pmax - _pmin).Length();
99 }
100
101 template <class Point>
102 bool
104 {
105 for (unsigned int i = 0; i < Dim; ++i)
106 if (_pmin[i] > p[i] || _pmax[i] < p[i])
107 {
108 return false;
109 }
110 return true;
111 }
112
113 template <class Point>
116 {
117 for (unsigned int i = 0; i < Dim; ++i)
118 {
119 if (_pmin[i] > p[i])
120 {
121 _pmin[i] = p[i];
122 }
123 if (_pmax[i] < p[i])
124 {
125 _pmax[i] = p[i];
126 }
127 }
128 return *this;
129 }
130}; // namespace GfxTL
uint8_t index
void Center(Point *center) const
Definition AABox.hpp:40
Point::ScalarType ScalarType
Definition AABox.h:23
void Split(unsigned int axis, ScalarType s, AABox< Point > *left, AABox< Point > *right) const
Definition AABox.hpp:22
Point operator[](unsigned int index) const
Definition AABox.hpp:49
bool IsInside(const Point &p) const
Definition AABox.hpp:103
AABox< Point > & operator+=(const PointType &p)
Definition AABox.hpp:115
Point PointType
Definition AABox.h:22
ScalarType DiagLength() const
Definition AABox.hpp:96
Point & Min()
Definition AABox.hpp:68
Point & Max()
Definition AABox.hpp:82
void Infinite()
Definition AABox.hpp:11
Definition AABox.h:10