11 #ifndef CUBBYFLOW_BOUNDING_BOX_IMPL_HPP 12 #define CUBBYFLOW_BOUNDING_BOX_IMPL_HPP 16 template <
typename T,
size_t N>
22 template <
typename T,
size_t N>
26 lowerCorner =
Min(point1, point2);
27 upperCorner =
Max(point1, point2);
30 template <
typename T,
size_t N>
32 : lowerCorner(other.lowerCorner), upperCorner(other.upperCorner)
37 template <
typename T,
size_t N>
39 : lowerCorner(std::move(other.lowerCorner)),
40 upperCorner(std::move(other.upperCorner))
45 template <
typename T,
size_t N>
54 template <
typename T,
size_t N>
57 lowerCorner = std::move(other.lowerCorner);
58 upperCorner = std::move(other.upperCorner);
63 template <
typename T,
size_t N>
66 return upperCorner[0] - lowerCorner[0];
69 template <
typename T,
size_t N>
73 return upperCorner[1] - lowerCorner[1];
76 template <
typename T,
size_t N>
80 return upperCorner[2] - lowerCorner[2];
83 template <
typename T,
size_t N>
86 return upperCorner[axis] - lowerCorner[axis];
89 template <
typename T,
size_t N>
92 for (
size_t i = 0; i < N; ++i)
104 template <
typename T,
size_t N>
107 for (
size_t i = 0; i < N; ++i)
109 if (upperCorner[i] < point[i] || lowerCorner[i] > point[i])
118 template <
typename T,
size_t N>
122 T max = std::numeric_limits<T>::max();
125 for (
size_t i = 0; i < N; ++i)
127 T near = (lowerCorner[i] - ray.
origin[i]) * rayInvDir[i];
128 T far = (upperCorner[i] - ray.
origin[i]) * rayInvDir[i];
132 std::swap(near, far);
135 min = near > min ? near : min;
136 max = far < max ? far : max;
147 template <
typename T,
size_t N>
154 T max = std::numeric_limits<T>::max();
157 for (
size_t i = 0; i < N; ++i)
159 T near = (lowerCorner[i] - ray.
origin[i]) * rayInvDir[i];
160 T far = (upperCorner[i] - ray.
origin[i]) * rayInvDir[i];
164 std::swap(near, far);
167 min = near > min ? near : min;
168 max = far < max ? far : max;
181 intersection.
near = max;
182 intersection.
far = std::numeric_limits<T>::max();
186 intersection.
near = min;
187 intersection.
far = max;
193 template <
typename T,
size_t N>
196 return (upperCorner + lowerCorner) /
static_cast<T
>(2);
199 template <
typename T,
size_t N>
205 template <
typename T,
size_t N>
211 template <
typename T,
size_t N>
214 lowerCorner = VectorType::MakeConstant(std::numeric_limits<T>::max());
215 upperCorner = VectorType::MakeConstant(-std::numeric_limits<T>::max());
218 template <
typename T,
size_t N>
221 lowerCorner =
Min(lowerCorner, point);
222 upperCorner =
Max(upperCorner, point);
225 template <
typename T,
size_t N>
232 template <
typename T,
size_t N>
235 lowerCorner -= delta;
236 upperCorner += delta;
239 template <
typename T,
size_t N>
244 for (
size_t i = 0; i < N; ++i)
246 ret[i] = lowerCorner[i] + (((
ONE_SIZE << i) & idx) != 0) *
247 (upperCorner[i] - lowerCorner[i]);
252 template <
typename T,
size_t N>
259 template <
typename T,
size_t N>
262 for (
size_t i = 0; i < N; ++i)
264 if (lowerCorner[i] >= upperCorner[i])
273 template <
typename T,
size_t N>
274 template <
typename U>
278 upperCorner.template CastTo<U>() };
ValueType LengthSquared() const
Definition: MatrixExpression-Impl.hpp:286
VectorType upperCorner
Upper corner of the bounding box.
Definition: BoundingBox.hpp:148
VectorType origin
The origin of the ray.
Definition: Ray.hpp:35
Class for N-D ray.
Definition: Ray.hpp:25
std::enable_if_t< std::is_arithmetic< T >::value, T > Clamp(T val, T low, T high)
Returns the clamped value.
Definition: MathUtils-Impl.hpp:166
BoundingBox()
Default constructor.
Definition: BoundingBox-Impl.hpp:17
T near
Distance to the first intersection point.
Definition: BoundingBox.hpp:33
N-D axis-aligned bounding box class.
Definition: BoundingBox.hpp:46
ValueType Length() const
Definition: MatrixExpression-Impl.hpp:278
constexpr size_t ONE_SIZE
One size_t.
Definition: Constants.hpp:47
constexpr auto Max(const MatrixExpression< T, Rows, Cols, M1 > &a, const MatrixExpression< T, Rows, Cols, M2 > &b)
Definition: MatrixExpression-Impl.hpp:1112
bool isIntersecting
True if the box and ray intersects.
Definition: BoundingBox.hpp:30
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
void Merge(RandomIterator a, size_t size, RandomIterator2 temp, CompareFunction compareFunction)
Definition: Parallel-Impl.hpp:107
T far
Distance to the second (and the last) intersection point.
Definition: BoundingBox.hpp:36
VectorType lowerCorner
Lower corner of the bounding box.
Definition: BoundingBox.hpp:145
constexpr auto Min(const MatrixExpression< T, Rows, Cols, M1 > &a, const MatrixExpression< T, Rows, Cols, M2 > &b)
Definition: MatrixExpression-Impl.hpp:1103
VectorType direction
The direction of the ray.
Definition: Ray.hpp:38
Box-ray intersection result.
Definition: BoundingBox.hpp:27