Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
bbox.h
Go to the documentation of this file.
1#ifndef BVH_V2_BBOX_H
2#define BVH_V2_BBOX_H
3
4#include "bvh/v2/vec.h"
5#include "bvh/v2/utils.h"
6
7#include <limits>
8
9namespace bvh::v2 {
10
11template <typename T, size_t N>
12struct BBox {
14
15 BBox() = default;
17 BVH_ALWAYS_INLINE explicit BBox(const Vec<T, N>& point) : BBox(point, point) {}
18
20 return extend(BBox(point));
21 }
22
24 min = robust_min(min, other.min);
25 max = robust_max(max, other.max);
26 return *this;
27 }
28
30 BVH_ALWAYS_INLINE Vec<T, N> get_center() const { return (max + min) * static_cast<T>(0.5); }
31
33 auto d = get_diagonal();
34 static_assert(N == 2 || N == 3);
35 if constexpr (N == 3) return (d[0] + d[1]) * d[2] + d[0] * d[1];
36 if constexpr (N == 2) return d[0] + d[1];
37 return static_cast<T>(0.);
38 }
39
40 BVH_ALWAYS_INLINE static constexpr BBox make_empty() {
41 return BBox(
42 Vec<T, N>(+std::numeric_limits<T>::max()),
43 Vec<T, N>(-std::numeric_limits<T>::max()));
44 }
45};
46
47} // namespace bvh::v2
48
49#endif
#define d(i)
Definition RSha256.hxx:102
#define N
Definition bbox.h:9
BVH_ALWAYS_INLINE T robust_max(T a, T b)
Definition utils.h:43
BVH_ALWAYS_INLINE T robust_min(T a, T b)
Definition utils.h:41
#define BVH_ALWAYS_INLINE
Definition platform.h:19
Vec< T, N > max
Definition bbox.h:13
BVH_ALWAYS_INLINE T get_half_area() const
Definition bbox.h:32
Vec< T, N > min
Definition bbox.h:13
BBox()=default
BVH_ALWAYS_INLINE BBox(const Vec< T, N > &point)
Definition bbox.h:17
BVH_ALWAYS_INLINE Vec< T, N > get_center() const
Definition bbox.h:30
BVH_ALWAYS_INLINE Vec< T, N > get_diagonal() const
Definition bbox.h:29
BVH_ALWAYS_INLINE BBox & extend(const Vec< T, N > &point)
Definition bbox.h:19
BVH_ALWAYS_INLINE BBox & extend(const BBox &other)
Definition bbox.h:23
BVH_ALWAYS_INLINE BBox(const Vec< T, N > &min, const Vec< T, N > &max)
Definition bbox.h:16
static BVH_ALWAYS_INLINE constexpr BBox make_empty()
Definition bbox.h:40