15#ifndef _CS237_AABB_HPP_
16#define _CS237_AABB_HPP_
19# error "cs237-aabb.hpp should not be included directly"
29 using vec3 = glm::vec<3, T, glm::defaultp>;
43 void clear () { this->_empty =
true; }
48 return (! this->_empty)
49 && (this->_min.x <= pt.x) && (pt.x <= this->_max.x)
50 && (this->_min.y <= pt.y) && (pt.y <= this->_max.y)
51 && (this->_min.z <= pt.z) && (pt.z <= this->_max.z);
58 (pt.A < this->_min.A) \
59 ? (this->_min.A - pt.A) \
60 : ((this->_max.A < pt.A) ? (pt.A - this->_max.A) : T(0))
63 T lenSq = dot(dv, dv);
79 else if (pt.x < this->_min.x) this->_min.x = pt.x;
80 else if (this->_max.x < pt.x) this->_max.x = pt.x;
81 if (pt.y < this->_min.y) this->_min.y = pt.y;
82 else if (this->_max.y < pt.y) this->_max.y = pt.y;
83 if (pt.z < this->_min.z) this->_min.z = pt.z;
84 else if (this->_max.z < pt.z) this->_max.z = pt.z;
91 if ((! this->_empty) && (! bb.
_empty)) {
92 this->_min = glm::min(this->_min, bb.
_min);
93 this->_max = glm::min(this->_max, bb.
_max);
95 else if (this->_empty) {
117 assert (! this->_empty);
124 assert (! this->_empty);
131 assert (! this->_empty);
132 return T(0.5) * (this->_min + this->
_max);
138 assert (! this->_empty);
144 assert (! this->_empty);
150 assert (! this->_empty);
156 assert (! this->_empty);
162 assert (! this->_empty);
168 assert (! this->_empty);
176 assert (! this->_empty);
177 assert ((0 <= i) && (i < 8));
179 (i & 4) ? this->_max.x : this->_min.x,
180 (i & 2) ? this->_max.y : this->_min.y,
181 (i & 1) ? this->_max.z : this->_min.z);
187 return std::array<vec3,8>{
188 vec3(this->_min.x, this->_min.y, this->_min.z),
189 vec3(this->_min.x, this->_min.y, this->_max.z),
190 vec3(this->_min.x, this->_max.y, this->_min.z),
191 vec3(this->_min.x, this->_max.y, this->_max.z),
192 vec3(this->_max.x, this->_min.y, this->_min.z),
193 vec3(this->_max.x, this->_min.y, this->_max.z),
194 vec3(this->_max.x, this->_max.y, this->_min.z),
195 vec3(this->_max.x, this->_max.y, this->_max.z)
211 if ((! bb1.
_empty) && (! bb2.empty)) {
214 else if (
bb1.empty) {
std::ostream & operator<<(std::ostream &s, __detail::AABB< T > const &bb)
print the axis-aligned bounding box to the output stream
AABB< T > operator+(AABB< T > const &bb1, AABB< T > &bb2)
Definition cs237-aabb.hpp:209
Definition cs237-aabb.hpp:22
Axis-Aligned Bounding Box parameterized over the scalar type.
Definition cs237-aabb.hpp:28
vec3 _max
Definition cs237-aabb.hpp:31
AABB(vec3 const &min, vec3 const &max)
Definition cs237-aabb.hpp:37
bool isEmpty() const
is the box empty
Definition cs237-aabb.hpp:40
T maxY() const
maximum Y-coordinate of the box
Definition cs237-aabb.hpp:160
AABB(AABB const &bbox)
Definition cs237-aabb.hpp:35
T minX() const
minimum X-coordinate of the box
Definition cs237-aabb.hpp:136
T maxX() const
maximum X-coordinate of the box
Definition cs237-aabb.hpp:154
void clear()
clear the box (i.e., make it empty)
Definition cs237-aabb.hpp:43
vec3 const & max() const
maximum extents of the box
Definition cs237-aabb.hpp:122
AABB()
Definition cs237-aabb.hpp:34
std::array< vec3, 8 > corners() const
return an array of the corners of the box
Definition cs237-aabb.hpp:185
T minZ() const
minimum Z-coordinate of the box
Definition cs237-aabb.hpp:148
T minY() const
minimum Y-coordinate of the box
Definition cs237-aabb.hpp:142
vec3 center() const
center of the box
Definition cs237-aabb.hpp:129
AABB & operator+=(AABB const &bb)
Definition cs237-aabb.hpp:89
vec3 const & min() const
minimum extents of the box
Definition cs237-aabb.hpp:115
T distanceToPt(vec3 const &pt) const
distance to a point; will be 0.0 if the point is inside the box
Definition cs237-aabb.hpp:55
vec3 _min
Definition cs237-aabb.hpp:31
AABB(vec3 const &pt)
Definition cs237-aabb.hpp:36
void addPt(vec3 const &pt)
extend this box as necessary to include the point
Definition cs237-aabb.hpp:72
bool includesPt(vec3 const &pt) const
is a point inside the box?
Definition cs237-aabb.hpp:46
T maxZ() const
maximum Z-coordinate of the box
Definition cs237-aabb.hpp:166
vec3 corner(int i) const
Definition cs237-aabb.hpp:174
bool _empty
Definition cs237-aabb.hpp:32
glm::vec< 3, T, glm::defaultp > vec3
Definition cs237-aabb.hpp:29