Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
AABB.h
1 #pragma once
2 #include <algorithm>
3 #include <limits>
4 
5 namespace WorldStone
6 {
16 template<typename T>
17 struct AABB
18 {
19  T xLower;
20  T yLower;
21  T xUpper;
22  T yUpper;
23 
24  T width() const { return xUpper - xLower; }
25  T height() const { return yUpper - yLower; }
26 
27  void maximize()
28  {
29  xLower = std::numeric_limits<T>::lowest();
30  yLower = std::numeric_limits<T>::lowest();
31  xUpper = std::numeric_limits<T>::max();
32  yUpper = std::numeric_limits<T>::max();
33  }
34 
35  void initializeForExtension() { *this = AABB::getInitializedForExtension(); }
36 
37  void extend(const AABB& other)
38  {
39  xLower = std::min(xLower, other.xLower);
40  yLower = std::min(yLower, other.yLower);
41  xUpper = std::max(xUpper, other.xUpper);
42  yUpper = std::max(yUpper, other.yUpper);
43  }
44 
54  static constexpr AABB getInitializedForExtension()
55  {
56  return {std::numeric_limits<T>::max(), std::numeric_limits<T>::max(),
57  std::numeric_limits<T>::lowest(), std::numeric_limits<T>::lowest()};
58  }
59 };
60 }
T xUpper
x upper bound : excluded
Definition: AABB.h:21
T yUpper
y upper bound : excluded
Definition: AABB.h:22
Axis-Aligned Bounding Box.
Definition: AABB.h:17
T xLower
x lower bound : excluded
Definition: AABB.h:19
static constexpr AABB getInitializedForExtension()
Used to initialize before computing the bounding box of objects.
Definition: AABB.h:54
T yLower
y lower bound : excluded
Definition: AABB.h:20