voxelTerrain
 All Classes Functions Variables Typedefs Enumerations Pages
axisAlignedBoxTemplate.hpp
1 #ifndef AXISALIGNEDBOXTEMPLATE_HPP
2 #define AXISALIGNEDBOXTEMPLATE_HPP
3 
4 #include "blub/serialization/access.hpp"
5 #include "blub/serialization/nameValuePair.hpp"
6 
7 #include "blub/core/globals.hpp"
8 
9 
10 namespace blub
11 {
12 
13 
14 template <typename vector3Type>
16 {
17 public:
19 
21  {
22 
23  }
24 
25  axisAlignedBoxTemplate(const vector3Type& min, const vector3Type& max)
26  : m_min(min)
27  , m_max(max)
28  {
29  ;
30  }
31 
32  bool operator == (const t_thisClass& other) const
33  {
34  return other.getMinimum() == m_min && other.getMaximum() == m_max;
35  }
36 
37  void setMinimumAndMaximum(const vector3Type& min, const vector3Type& max)
38  {
39  m_min = min;
40  m_max = max;
41  }
42 
43  const vector3Type& getMinimum(void) const
44  {
45  return m_min;
46  }
47 
48  const vector3Type& getMaximum(void) const
49  {
50  return m_max;
51  }
52 
53  vector3Type getSize(void) const
54  {
55  return m_max - m_min;
56  }
57 
58  vector3Type getCenter(void) const
59  {
60  return (m_min + m_max) / 2;
61  }
62 
63  bool isInside(const vector3Type& in) const
64  {
65  return in >= m_min && in <= m_max;
66  }
67 
68  bool isInside(const t_thisClass& in) const
69  {
70  return in.isInside(m_min) && in.isInside(m_max);
71  }
72 
73  void extend(const t_thisClass& ext)
74  {
75  if (!ext.isValid())
76  {
77  return;
78  }
79  extend(ext.getMinimum());
80  extend(ext.getMaximum());
81  }
82  void extend(const vector3Type& ext)
83  {
84  if (isValid())
85  {
86  setMinimumAndMaximum(m_min.getMinimum(ext), m_max.getMaximum(ext));
87  return;
88  }
89  setMinimumAndMaximum(ext, ext);
90  }
91 
92  bool isValid() const
93  {
94  return m_max >= m_min;
95  }
96 
97  typename vector3Type::t_valueType getVolume()
98  {
99  const vector3Type size(getSize());
100  return size.x * size.y * size.z;
101  }
102 
103 
104 private:
105  BLUB_SERIALIZATION_ACCESS
106 
107  template <class formatType>
108  void serialize(formatType & readWrite, const uint32& version)
109  {
110  (void)version;
111 
112  readWrite & serialization::nameValuePair::create("min", m_min);
113  readWrite & serialization::nameValuePair::create("max", m_max);
114  }
115 
116 
117 protected:
118  vector3Type m_min;
119  vector3Type m_max;
120 
121 };
122 
123 
124 }
125 
126 
127 #endif // AXISALIGNEDBOXTEMPLATE_HPP
Definition: axisAlignedBoxTemplate.hpp:15
Definition: deadlineTimer.hpp:10