BoundingBox3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: BoundingBox3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-D axis-aligned bounding box class.
6 > Created Time: 2017/03/29
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_BOUNDING_BOX3_H
10 #define CUBBYFLOW_BOUNDING_BOX3_H
11 
13 #include <Core/Ray/Ray3.h>
14 #include <Core/Vector/Vector3.h>
15 
16 #include <limits>
17 
18 namespace CubbyFlow
19 {
25  template <typename T>
27  {
29  bool isIntersecting = false;
30 
32  T near = std::numeric_limits<T>::max();
33 
35  T far = std::numeric_limits<T>::max();
36  };
37 
43  template <typename T>
44  class BoundingBox<T, 3>
45  {
46  public:
49 
52 
54  BoundingBox();
55 
57  BoundingBox(const Vector3<T>& point1, const Vector3<T>& point2);
58 
60  BoundingBox(const BoundingBox& other);
61 
63  T GetWidth() const;
64 
66  T GetHeight() const;
67 
69  T GetDepth() const;
70 
72  T Length(size_t axis);
73 
75  bool Overlaps(const BoundingBox& other) const;
76 
78  bool Contains(const Vector3<T>& point) const;
79 
81  bool Intersects(const Ray3<T>& ray) const;
82 
87  BoundingBoxRayIntersection3<T> ClosestIntersection(const Ray3<T>& ray) const;
88 
90  Vector3<T> MidPoint() const;
91 
93  T DiagonalLength() const;
94 
96  T DiagonalLengthSquared() const;
97 
99  void Reset();
100 
102  void Merge(const Vector3<T>& point);
103 
105  void Merge(const BoundingBox& other);
106 
110  void Expand(T delta);
111 
113  Vector3<T> Corner(size_t idx) const;
114 
116  Vector3<T> Clamp(const Vector3<T>& pt) const;
117 
119  bool IsEmpty() const;
120  };
121 
123  template <typename T> using BoundingBox3 = BoundingBox<T, 3>;
124 
127 
130 
133 
136 }
137 
139 
140 #endif
3-D vector class.
Definition: Vector3.h:26
bool Contains(const VectorType &point) const
Returns true if the input point is inside of this box.
Definition: BoundingBox-Impl.h:54
T near
Distance to the first intersection point.
Definition: BoundingBox3.h:32
bool isIntersecting
True if the box and ray intersects.
Definition: BoundingBox3.h:29
VectorType MidPoint() const
Returns the mid-point of this box.
Definition: BoundingBox-Impl.h:68
BoundingBox()
Default constructor.
Definition: BoundingBox-Impl.h:17
Vector3< T > lowerCorner
Lower corner of the bounding box.
Definition: BoundingBox3.h:48
Generic N-D axis-aligned bounding box class.
Definition: BoundingBox.h:23
void Reset()
Resets this box to initial state (min=infinite, max=-infinite).
Definition: BoundingBox-Impl.h:107
T far
Distance to the second (and the last) intersection point.
Definition: BoundingBox3.h:35
Definition: pybind11Utils.h:24
T Clamp(T val, T low, T high)
Returns the clamped value.
Definition: MathUtils-Impl.h:123
Vector3< T > upperCorner
Upper corner of the bounding box.
Definition: BoundingBox3.h:51
3-D axis-aligned bounding box class.
Definition: BoundingBox3.h:44
T DiagonalLength() const
Returns diagonal length of this box.
Definition: BoundingBox-Impl.h:81
void Merge(const VectorType &point)
Merges this and other point.
Definition: BoundingBox-Impl.h:117
3-D box-ray intersection result.
Definition: BoundingBox3.h:26
bool Overlaps(const BoundingBox &other) const
Returns true of this box and other box overlaps.
Definition: BoundingBox-Impl.h:40
void Expand(T delta)
Definition: BoundingBox-Impl.h:137
T DiagonalLengthSquared() const
Returns squared diagonal length of this box.
Definition: BoundingBox-Impl.h:94
Class for 3-D ray.
Definition: Ray3.h:23