Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop committed Dec 26, 2023
1 parent 73c8d03 commit 6c557c6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/geometry/ArborX_Ray.hpp
Expand Up @@ -363,8 +363,7 @@ bool intersection(Ray const &ray,
w = (double)B[0] * A[1] - (double)B[1] * A[0];
}

constexpr auto inf =
Details::KokkosExt::ArithmeticTraits::infinity<float>::value;
constexpr auto inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
tmin = inf;
tmax = -inf;

Expand Down Expand Up @@ -528,6 +527,8 @@ KOKKOS_INLINE_FUNCTION bool solveQuadratic(float const a, float const b,
KOKKOS_INLINE_FUNCTION bool intersection(Ray const &ray, Sphere const &sphere,
float &tmin, float &tmax)
{
namespace KokkosExt = ArborX::Details::KokkosExt;

auto const &r = sphere.radius();

// Vector oc = (origin_of_ray - center_of_sphere)
Expand All @@ -541,12 +542,11 @@ KOKKOS_INLINE_FUNCTION bool intersection(Ray const &ray, Sphere const &sphere,
{
// ensures that tmin <= tmax
if (tmin > tmax)
Details::KokkosExt::swap(tmin, tmax);
KokkosExt::swap(tmin, tmax);

return true;
}
constexpr auto inf =
Details::KokkosExt::ArithmeticTraits::infinity<float>::value;
constexpr auto inf = KokkosExt::ArithmeticTraits::infinity<float>::value;
tmin = inf;
tmax = -inf;
return false;
Expand All @@ -557,12 +557,14 @@ KOKKOS_INLINE_FUNCTION void
overlapDistance(Ray const &ray, Geometry const &geometry, float &length,
float &distance_to_origin)
{
namespace KokkosExt = ArborX::Details::KokkosExt;

float tmin;
float tmax;
if (intersection(ray, geometry, tmin, tmax) && (tmin <= tmax && tmax >= 0))
{
// Overlap [tmin, tmax] with [0, +inf)
tmin = Details::KokkosExt::max(0.f, tmin);
tmin = KokkosExt::max(0.f, tmin);
// As direction is normalized,
// |(o + tmax*d) - (o + tmin*d)| = tmax - tmin
length = tmax - tmin;
Expand All @@ -571,8 +573,7 @@ overlapDistance(Ray const &ray, Geometry const &geometry, float &length,
else
{
length = 0;
distance_to_origin =
Details::KokkosExt::ArithmeticTraits::infinity<float>::value;
distance_to_origin = KokkosExt::ArithmeticTraits::infinity<float>::value;
}
}

Expand Down

0 comments on commit 6c557c6

Please sign in to comment.