Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 972292af776160a5012d3b5c8768a21ab9b74c99 (plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
   math/boundingbox3f.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#ifndef __INCLUDED_MATH_BOUNDINGBOX3F_H__
#define __INCLUDED_MATH_BOUNDINGBOX3F_H__

#include "math/vector3f.h"

namespace math {

/**
 * @brief a bounding box class
 */
class BoundingBox3f {
public:
	BoundingBox3f();
	BoundingBox3f(const Vector3f &center);
	
	/**
	 * @brief returns the minimum coordinates of the bounding box
	 */
	inline const Vector3f & min() const {
		return boundingbox_min;
	}
	
	/**
	 * @brief returns the maximum coordinates of the bounding box
	 */
	inline const Vector3f & max() const {
		return boundingbox_max;
	}

	/**
	 * @brief test if a point is located inside the bounding box
	 */
	inline const bool inside(const Vector3f & point) const {
		for (size_t i =0; i < 3; i++) {
			if ((point[i] < boundingbox_min[i]) || (point[i] > boundingbox_max[i])) {
				return false;
			}
		}
		return true;
	}
	
	/**
	 * @brief test if a point is located outside the bounding box
	 */
	inline const bool outside(const Vector3f & point) const {
		for (size_t i =0; i < 3; i++) {
			if ((point[i] < boundingbox_min[i]) || (point[i] > boundingbox_max[i])) {
				return true;
			}
		}
		return false;
	}
	
	void assign(const BoundingBox3f & other);
	
	void assign(const Vector3f & min, const Vector3f & max);
	
	void assign(const Vector3f &center);
	
	void assign(const float min, const float max);
	
	void clear();
	
	/**
	 * @brief expand the bounding box to contain a point
	 */
	inline void expand(const Vector3f & point) {
		for (size_t i =0; i < 3; i++) {
			if (point[i] < boundingbox_min[i]) {
				boundingbox_min[i] = point[i];
			}
			
			if (point[i] > boundingbox_max[i]) {
				boundingbox_max[i] = point[i];
			}
		}
	}
	
	/**
	 * @brief expand the bounding box to contain another bounding box
	 */
	inline void expand(const Vector3f & min, const Vector3f & max) {
		for (size_t i =0; i < 3; i++) {
			if (min[i] < boundingbox_min[i]) {
				boundingbox_min[i] = min[i];
			}
			
			if (max[i] > boundingbox_max[i]) {
				boundingbox_max[i] = max[i];
			}
		}
	}
	
	/**
	 * @brief expand the bounding box to contain another bounding box
	 */
	inline void expand(const BoundingBox3f & other) {
		expand(other.boundingbox_min, other.boundingbox_max);
	}
	
	/**
	 * @brief expand the bounding box by a range
	 */
	inline void expand(const float range) {
		for (size_t i =0; i < 3; i++) {
			boundingbox_min[i] -= range;
			boundingbox_max[i] += range;
		}
		
	}
	
private:
	Vector3f	boundingbox_min;
	Vector3f	boundingbox_max;
};

} // namespace math
#endif // __INCLUDED_MATH_BOUNDINGBOX3F_H__