28 : lower(owl::common::empty_bounds_lower<T>()),
29 upper(owl::common::empty_bounds_upper<T>())
31 inline __both__
interval(T begin, T end) : begin(begin), end(end) {}
44 inline __both__
bool contains(
const T &t)
const {
return t >= lower && t <= upper; }
45 inline __both__
bool is_empty()
const {
return begin > end; }
46 inline __both__
bool empty()
const {
return begin > end; }
47 inline __both__ T center()
const {
return (begin+end)/2; }
48 inline __both__ T span()
const {
return end - begin; }
49 inline __both__ T diagonal()
const {
return end - begin; }
51 { lower = min(lower,t); upper = max(upper,t);
return *
this; }
53 { lower = min(lower,t.lower); upper = max(upper,t.upper);
return *
this; }
59 return interval<T>(0.f,owl::common::open_range_upper<T>());
64 inline __both__ std::ostream &operator<<(std::ostream &o,
const interval<T> &b)
67 o <<
"[" << b.lower <<
":" << b.upper <<
"]";
73 inline __both__
interval<T> build_interval(
const T &a,
const T &b)
77 inline __both__ interval<T> intersect(
const interval<T> &a,
const interval<T> &b)
78 {
return interval<T>(max(a.lower,b.lower),min(a.upper,b.upper)); }
81 inline __both__ interval<T> operator-(
const interval<T> &a,
const T &b)
82 {
return interval<T>(a.lower-b,a.upper-b); }
85 inline __both__ interval<T> operator*(
const interval<T> &a,
const T &b)
86 {
return build_interval<T>(a.lower*b,a.upper*b); }
89 inline __both__
bool operator==(
const interval<T> &a,
const interval<T> &b)
90 {
return a.lower == b.lower && a.upper == b.upper; }
93 inline __both__
bool operator!=(
const interval<T> &a,
const interval<T> &b)
101 typedef typename T::scalar_t scalar_t;
102 enum { dims = T::dims };
104 inline __both__
box_t()
105 : lower(owl::common::empty_bounds_lower<typename T::scalar_t>()),
106 upper(owl::common::empty_bounds_upper<typename T::scalar_t>())
115 explicit inline __both__
box_t(
const vec_t &v)
121 inline __both__
box_t(
const vec_t &lo,
const vec_t &hi)
128 {
return box_t(min(lower,other),max(upper,other)); }
131 {
return box_t(min(lower,other.lower),max(upper,other.upper)); }
136 { lower = min(lower,other); upper = max(upper,other);
return *
this; }
139 { lower = min(lower,other.lower); upper = max(upper,other.upper);
return *
this; }
148 inline __both__
bool contains(
const vec_t &point)
const
149 {
return !(any_less_than(point,lower) || any_greater_than(point,upper)); }
151 inline __both__
bool overlaps(
const box_t &other)
const
152 {
return !(any_less_than(other.upper,lower) || any_greater_than(other.lower,upper)); }
154 inline __both__ vec_t center()
const {
return (lower+upper)/(
typename vec_t::scalar_t)2; }
155 inline __both__ vec_t span()
const {
return upper-lower; }
156 inline __both__ vec_t size()
const {
return upper-lower; }
158 inline __both__
typename long_type_of<typename T::scalar_t>::type volume()
const
159 {
return owl::common::volume(size()); }
161 inline __both__
bool empty()
const {
return any_less_than(upper,lower); }
171 inline __both__
typename long_type_of<T>::type area(
const box_t<vec_t<T,2>> &b)
172 {
return area(b.upper - b.lower); }
175 inline __both__
typename long_type_of<T>::type area(
const box_t<vec_t<T,3>> &b)
177 const vec_t<T,3> diag = b.upper - b.lower;
178 return T(2)*(area(vec_t<T,2>(diag.x,diag.y))+
179 area(vec_t<T,2>(diag.y,diag.z))+
180 area(vec_t<T,2>(diag.z,diag.x)));
184 inline __both__
typename long_type_of<T>::type volume(
const box_t<vec_t<T,3>> &b)
186 const vec_t<T,3> diag = b.upper - b.lower;
187 return diag.x*diag.y*diag.z;
191 inline __both__ std::ostream &operator<<(std::ostream &o,
const box_t<T> &b)
194 o <<
"[" << b.lower <<
":" << b.upper <<
"]";
200 inline __both__ box_t<T> intersection(
const box_t<T> &a,
const box_t<T> &b)
201 {
return box_t<T>(max(a.lower,b.lower),min(a.upper,b.upper)); }
204 inline __both__
bool operator==(
const box_t<T> &a,
const box_t<T> &b)
205 {
return a.lower == b.lower && a.upper == b.upper; }
208 inline __both__
bool operator!=(
const box_t<T> &a,
const box_t<T> &b)
209 {
return !(a == b); }
218#define _define_box_types(T,t) \
219 typedef box_t<vec_t<T,2>> box2##t; \
220 typedef box_t<vec_t<T,3>> box3##t; \
221 typedef box_t<vec_t<T,4>> box4##t; \
222 typedef box_t<vec3a_t<T>> box3##t##a; \
224 _define_box_types(
bool ,b);
225 _define_box_types(int8_t ,c);
226 _define_box_types(int16_t ,s);
227 _define_box_types(int32_t ,i);
228 _define_box_types(int64_t ,l);
229 _define_box_types(uint8_t ,uc);
230 _define_box_types(uint16_t,us);
231 _define_box_types(uint32_t,ui);
232 _define_box_types(uint64_t,ul);
233 _define_box_types(
float,f);
234 _define_box_types(
double,d);
236#undef _define_box_types
__both__ box_t & extend(const vec_t &other)
Definition: box.h:135
__both__ box_t(const vec_t &lo, const vec_t &hi)
Definition: box.h:121
__both__ box_t(const vec_t &v)
Definition: box.h:115
__both__ interval< scalar_t > get_slab(const uint32_t dim)
Definition: box.h:143
__both__ box_t including(const vec_t &other) const
Definition: box.h:127
__both__ box_t including(const box_t &other) const
Definition: box.h:130
__both__ box_t & extend(const box_t &other)
Definition: box.h:138