36 using Tscal =
typename T_prop::component_type;
48 inline Ray(T origin, T direction)
49 : origin(origin), direction(direction), inv_direction(Tscal{1.} / direction) {
51 Tscal f = sycl::length(direction);
55 this->inv_direction *= f;
69 using Tscal =
typename T_prop::component_type;
76 T get_ez() {
return sycl::cross(e_x, e_y); }
84 inline RingRay(T center, Tscal radius, T e_x, T e_y)
85 : center(center), radius(radius), e_x(e_x), e_y(e_y) {}
102 using Tscal =
typename T_prop::component_type;
107 inline AABB() =
default;
131 inline AABB(std::tuple<T, T> range)
154 inline Tscal get_radius()
const {
return sycl::length(
delt()) / 2; }
216 Tb_prop::dim == T_prop::dim,
"you cannot change the dimension in convert");
219 lower.template convert<Tb_prop::component_type>(),
220 upper.template convert<Tb_prop::component_type>()};
235 return {sham::max(
lower, other.lower), sham::min(
upper, other.upper)};
246 return sham::vec_compare_leq(
lower, other.lower)
247 && sham::vec_compare_geq(
upper, other.upper);
257 return sham::vec_compare_leq(
lower, point) && sham::vec_compare_g(
upper, point);
348 return sham::equals(
lower, other.lower) && sham::equals(
upper, other.upper);
359 Tscal tx1 = (lower.x() - ray.origin.x()) * ray.inv_direction.x();
360 Tscal tx2 = (upper.x() - ray.origin.x()) * ray.inv_direction.x();
362 tmin = sycl::max(tmin, sycl::min(tx1, tx2));
363 tmax = sycl::min(tmax, sycl::max(tx1, tx2));
365 Tscal ty1 = (lower.y() - ray.origin.y()) * ray.inv_direction.y();
366 Tscal ty2 = (upper.y() - ray.origin.y()) * ray.inv_direction.y();
368 tmin = sycl::max(tmin, sycl::min(ty1, ty2));
369 tmax = sycl::min(tmax, sycl::max(ty1, ty2));
371 Tscal tz1 = (lower.z() - ray.origin.z()) * ray.inv_direction.z();
372 Tscal tz2 = (upper.z() - ray.origin.z()) * ray.inv_direction.z();
374 tmin = sycl::max(tmin, sycl::min(tz1, tz2));
375 tmax = sycl::min(tmax, sycl::max(tz1, tz2));
383 T aabb_center = get_center();
384 Tscal aabb_radius = get_radius();
386 T r_center = ring_ray.center - aabb_center;
388 Tscal x_val = sycl::dot(r_center, ring_ray.e_x);
389 Tscal y_val = sycl::dot(r_center, ring_ray.e_y);
390 Tscal z_val = sycl::dot(r_center, ring_ray.get_ez());
392 Tscal r_val = sycl::sqrt(x_val * x_val + y_val * y_val);
393 Tscal delta_r = r_val - ring_ray.radius;
394 Tscal rab2_ring = z_val * z_val + delta_r * delta_r;
396 return rab2_ring <= aabb_radius * aabb_radius;
Shamrock assertion utility.
#define SHAM_ASSERT(x)
Shorthand for SHAM_ASSERT_NAMED without a message.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
namespace for math utility
Axis-Aligned bounding box.
typename T_prop::component_type Tscal
Scalar type of the coordinates.
T delt() const
Returns the delta of the AABB.
T get_center() const noexcept
Returns the center of the AABB.
bool is_surface() const noexcept
Checks if the AABB is a surface.
T clamp_coord(T coord) const noexcept
Clamp a coordinate to the box.
bool is_surface_or_volume() const noexcept
Checks if the AABB is a surface or a volume.
bool contains(AABB other) const noexcept
Check if AABB fully contains another AABB.
bool intersect_ray(Ray< T > ray) const noexcept
Check if the ray intersect the AABB.
bool is_volume_not_null() const noexcept
Checks if the AABB has a non-zero volume.
AABB(std::pair< T, T > range)
Construct an AABB from a pair of lower and upper bounds.
bool operator!=(const AABB< T > &other) const noexcept
not equal operator
AABB(T lower, T upper)
Construct an AABB from lower and upper bounds.
AABB< Tb > convert()
Converts the AABB to a different type.
T lower
Lower bound of the AABB.
AABB expand_all(Tscal value)
Expand the AABB by a given value on all dimensions.
bool intersect_ring_ray_approx(RingRay< T > ring_ray) const noexcept
Check if the ring ray intersect the AABB.
bool contains_asymmetric(T point) const noexcept
Check if point is in AABB using half-open interval [lower, upper)
bool is_not_empty() const noexcept
Checks if the AABB is non-empty.
Tscal get_volume()
Returns the volume of the AABB.
bool operator==(const AABB< T > &other) const noexcept
equal operator
AABB(std::tuple< T, T > range)
Construct an AABB from a tuple of lower and upper bounds.
T upper
Upper bound of the AABB.
AABB get_intersect(AABB other) const noexcept
Compute the intersection of two AABB.
T sum_bounds() const noexcept
Returns the sum of the lower and upper bounds of the AABB.
Ray representation for intersection testing.
Ray(T origin, T direction)
Construct a normalized ray from origin and direction.
Ring ray representation for intersection testing.
RingRay(T center, Tscal radius, T e_x, T e_y)
Construct a ring ray from center, e_x, and e_y.