Skip to content

Commit

Permalink
Use fast precision for bounding box intersection calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottbiondo committed Jan 30, 2025
1 parent 74f8804 commit 7d7159a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/orange/BoundingBoxUtils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,21 @@ inline bool encloses(BoundingBox<T> const& big, BoundingBox<T> const& small)
* intersection, the result will be inf.
*/
template<class T, class U>
inline CELER_FUNCTION U calc_dist_to_inside(BoundingBox<T> const& bbox,
inline CELER_FUNCTION T calc_dist_to_inside(BoundingBox<T> const& bbox,
Array<U, 3> const& pos,
Array<U, 3> const& dir)
{
CELER_EXPECT(!is_inside(bbox, pos));

// Test if an intersection is outside the bbox for a given axis
auto out_of_bounds = [&bbox](U intersect, int ax) {
auto out_of_bounds = [&bbox](T intersect, int ax) {
return !(intersect >= bbox.lower()[ax]
&& intersect <= bbox.upper()[ax]);
};

// Check that the intersection point occurs within the region
// bounded by the planes of the other two axes
auto in_bounds = [&](int ax, U dist) {
auto in_bounds = [&](int ax, T dist) {
for (auto other_ax : range(to_int(Axis::size_)))
{
if (other_ax == ax)
Expand All @@ -256,8 +256,8 @@ inline CELER_FUNCTION U calc_dist_to_inside(BoundingBox<T> const& bbox,
};

// Loop over all 6 planes to find the minimum intersection
U min_dist = numeric_limits<U>::infinity();
for (auto bound : range(to_int(Bound::size_)))
T min_dist = numeric_limits<T>::infinity();
for (auto bound : range(Bound::size_))
{
for (auto ax : range(to_int(Axis::size_)))
{
Expand All @@ -267,10 +267,10 @@ inline CELER_FUNCTION U calc_dist_to_inside(BoundingBox<T> const& bbox,
continue;
}

U dist = (bbox.point(static_cast<Bound>(bound))[ax] - pos[ax])
T dist = (bbox.point(static_cast<Bound>(bound))[ax] - pos[ax])
/ dir[ax];

if (dist < 0)
if (dist <= 0)
{
// Short circut if the plane is behind us
continue;
Expand Down
5 changes: 5 additions & 0 deletions src/orange/detail/BIHBuilder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ namespace detail
* node with all volumes in the stored inf_vols. This final case is useful in
* the event that an ORANGE geometry is created via a method where volume
* bounding boxes are not availible.
*
* Bounding boxes supplied to this builder should "bumped," i.e. expanded
* outward by at least floating-point epsilson from the volumes they bound.
* This eliminates the possiblity of accidently missing a volume during
* tracking.
*/
class BIHBuilder
{
Expand Down

0 comments on commit 7d7159a

Please sign in to comment.