Imath
<navlinks>
<page>

# Box Functions

Functions that operate on bounding boxes.

    #include <Imath/ImathBoxAlgo.h>

template<class T>
inline constexpr T Imath::clip(const T &p, const Box<T> &box) noexcept

  Clip the coordinates of a point, `p`, against a `Box<T>`, `box`.

  Return the closest point to `p` that is inside the box.

template<class T>
inline constexpr T Imath::closestPointInBox(const T &p, const Box<T> &box) noexcept

  Return the point in or on the `Box<T>`, `box`, that is closesest to the point, `p`.

template<class S, class T>
Box<Vec3<S>> Imath::transform(const Box<Vec3<S>> &box, const Matrix44<T> &m) noexcept

  Transform a 3D box by a matrix, and compute a new box that tightly encloses the transformed box.

  Return the transformed box.

  If `m` is an affine transform, then we use James Arvo’s fast method as described in “Graphics Gems”, Academic Press, 1990, pp. 548-550.

  A transformed empty box is still empty, and a transformed infinite box is still infinite.

template<class S, class T>
Box<Vec3<S>> Imath::affineTransform(const Box<Vec3<S>> &box, const Matrix44<T> &m) noexcept

  Transform a 3D box by a matrix whose rightmost column `(0 0 0 1)`, and compute a new box that tightly encloses the transformed box.

  Return the transformed box.

  As in the transform() function, use James Arvo’s fast method if possible.

  A transformed empty or infinite box is still empty or infinite.

template<class T>
constexpr bool Imath::findEntryAndExitPoints(const Line3<T> &r, const Box<Vec3<T>> &b, Vec3<T> &entry, Vec3<T> &exit) noexcept

  Compute the points where a ray, `r`, enters and exits a 3D box, `b`:

  Return true if the ray starts inside the box or if the ray starts outside and intersects the box, or return false otherwise (that is, if the ray does not intersect the box).

  The entry and exit points are the points on two of the faces of the box when the function returns true (the entry end exit points may be on either side of the ray’s origin), or undefined if the the function returns false.

template<class T>
constexpr bool Imath::intersects(const Box<Vec3<T>> &b, const Line3<T> &r, Vec3<T> &ip) noexcept

  Intersect a ray, `r`, with a 3D box, `b, and compute the intersection point, returned in`ip`.

  The intersection point is

  - the ray’s origin if the ray starts inside the box

  - a point on one of the faces of the box if the ray starts outside the box

  - undefined when intersect() returns false

  Returns:

    - true if the ray starts inside the box or if the ray starts outside and intersects the box

    - false if the ray starts outside the box and intersects it, but the intersection is behind the ray’s origin.

    - false if the ray starts outside and does not intersect it

</page>