Celeritas  0.5.0-56+6b053cd
Classes | Functions
BoundingBoxUtils.hh File Reference

Host-only utilities for bounding boxes. More...

#include <cmath>
#include <iosfwd>
#include "corecel/cont/Range.hh"
#include "corecel/math/Algorithms.hh"
#include "corecel/math/SoftEqual.hh"
#include "geocel/BoundingBox.hh"
#include "OrangeTypes.hh"
This graph shows which files directly or indirectly include this file:

Classes

class  celeritas::BoundingBoxBumper< T, U >
 Bump a bounding box outward and possibly convert to another type. More...
 

Functions

template<class T >
bool celeritas::is_infinite (BoundingBox< T > const &bbox)
 Check if a bounding box spans (-inf, inf) in every direction.
 
template<class T >
bool celeritas::is_finite (BoundingBox< T > const &bbox)
 Check if a bounding box has no infinities. More...
 
template<class T >
bool celeritas::is_degenerate (BoundingBox< T > const &bbox)
 Check if a bounding box has zero length in any direction. More...
 
template<class T >
Array< T, 3 > celeritas::calc_center (BoundingBox< T > const &bbox)
 Calculate the center of a bounding box. More...
 
template<class T >
Array< T, 3 > celeritas::calc_half_widths (BoundingBox< T > const &bbox)
 Calculate the half widths of the bounding box. More...
 
template<class T >
celeritas::calc_surface_area (BoundingBox< T > const &bbox)
 Calculate the surface area of a bounding box. More...
 
template<class T >
celeritas::calc_volume (BoundingBox< T > const &bbox)
 Calculate the volume of a bounding box. More...
 
template<class T >
constexpr BoundingBox< T > celeritas::calc_union (BoundingBox< T > const &a, BoundingBox< T > const &b)
 Calculate the smallest bounding box enclosing two bounding boxes.
 
template<class T >
constexpr BoundingBox< T > celeritas::calc_intersection (BoundingBox< T > const &a, BoundingBox< T > const &b)
 Calculate the intersection of two bounding boxes. More...
 
template<class T >
bool celeritas::encloses (BoundingBox< T > const &big, BoundingBox< T > const &small)
 Check if all points inside the small bbox are in the big bbox. More...
 
template<class T , class U >
celeritas::calc_dist_to_inside (BoundingBox< T > const &bbox, Array< U, 3 > const &pos, Array< U, 3 > const &dir)
 Calculate the distance to the inside of the bbox from a pos and dir. More...
 
BBox celeritas::calc_transform (Translation const &tr, BBox const &a)
 Calculate the bounding box of a translated box.
 
BBox celeritas::calc_transform (Transformation const &tr, BBox const &a)
 Calculate the axis-aligned bounding box of a transformed box. More...
 
template<class T >
std::ostream & celeritas::operator<< (std::ostream &os, BoundingBox< T > const &bbox)
 Write a bounding box to a stream.
 

Detailed Description

Host-only utilities for bounding boxes.

Function Documentation

◆ calc_center()

template<class T >
Array<T, 3> celeritas::calc_center ( BoundingBox< T > const &  bbox)
inline

Calculate the center of a bounding box.

Precondition
The bounding box cannot be null

◆ calc_dist_to_inside()

template<class T , class U >
U celeritas::calc_dist_to_inside ( BoundingBox< T > const &  bbox,
Array< U, 3 > const &  pos,
Array< U, 3 > const &  dir 
)
inline

Calculate the distance to the inside of the bbox from a pos and dir.

The supplied position is expected to be outside of the bbox. If there is no intersection, the result will be inf.

◆ calc_half_widths()

template<class T >
Array<T, 3> celeritas::calc_half_widths ( BoundingBox< T > const &  bbox)
inline

Calculate the half widths of the bounding box.

Precondition
The bounding box cannot be null

◆ calc_intersection()

template<class T >
constexpr BoundingBox<T> celeritas::calc_intersection ( BoundingBox< T > const &  a,
BoundingBox< T > const &  b 
)
inlineconstexpr

Calculate the intersection of two bounding boxes.

If there is no intersection, the result will be a null bounding box.

◆ calc_surface_area()

template<class T >
T celeritas::calc_surface_area ( BoundingBox< T > const &  bbox)
inline

Calculate the surface area of a bounding box.

Precondition
The bounding box cannot be null

◆ calc_transform()

BBox celeritas::calc_transform ( Transformation const &  tr,
BBox const &  a 
)

Calculate the axis-aligned bounding box of a transformed box.

Transforming a box usually results in an oriented bounding box, but sometimes that OBB is also an AABB. This function implicitly creates the transformed bounding box and creates an AABB that encompasses that box.

The result returns an exactly transformed bounding box for axis-aligned rotations. To achieve exactness for semi-infinite bounding boxes, this method has a custom implementation of GEMV for applying exact rotations if the matrix representation simply switches vector entries or flips their sign. Without the complication, floating point arithmetic results in NaN from multiplying zeroes (in the matrix) by the infinite values.

◆ calc_volume()

template<class T >
T celeritas::calc_volume ( BoundingBox< T > const &  bbox)
inline

Calculate the volume of a bounding box.

Precondition
The bounding box cannot be null

◆ encloses()

template<class T >
bool celeritas::encloses ( BoundingBox< T > const &  big,
BoundingBox< T > const &  small 
)
inline

Check if all points inside the small bbox are in the big bbox.

All bounding boxes should enclose a "null" bounding box (there are no points in the null box, so no points are outside the big box). The null bounding box will enclose no real bounding boxes. Comparing two null bounding boxes is unspecified (forbidden for now).

◆ is_degenerate()

template<class T >
bool celeritas::is_degenerate ( BoundingBox< T > const &  bbox)
inline

Check if a bounding box has zero length in any direction.

Precondition
The bounding box cannot be null

◆ is_finite()

template<class T >
bool celeritas::is_finite ( BoundingBox< T > const &  bbox)
inline

Check if a bounding box has no infinities.

Precondition
The bounding box cannot be null