template <typename Scalar>
muu::bounding_box struct

An axis-aligned bounding box.

Template parameters
Scalar The bounding box's scalar component type. Must be a floating-point type.
Image

Public types

using constants = muu::constants<bounding_box>
Compile-time bounding box constants.
using scalar_type = Scalar
The bounding box's scalar type.
using vector_type = vector<scalar_type, 3>
The three-dimensional muu::vector with the same scalar_type as the bounding box.

Public static functions

static auto from_min_max(const vector_type& min_, const vector_type& max_) -> bounding_box constexpr noexcept
Constructs a bounding box from min and max corners.
static auto from_obb(const oriented_bounding_box<scalar_type>& obb) -> bounding_box constexpr noexcept
Constructs a bounding box completely containing an oriented bounding-box.
template <typename... T>
static auto from_points(const vector_type& pt0, const vector_type& pt1, const T&... pts) -> bounding_box constexpr noexcept
Constructs a bounding box fitting two or more points.
static auto from_points(const vector_type* begin, const vector_type* end) -> bounding_box constexpr noexcept
Constructs a bounding box fitting a range of points.
template <size_t N>
static auto from_points(const vector_type(&points)[N]) -> bounding_box constexpr noexcept
Constructs a bounding box fitting an array of points.
static auto from_sphere(const bounding_sphere<scalar_type>& bs) -> bounding_box constexpr noexcept
Constructs a bounding box completely containing a bounding sphere.

Constructors, destructors, conversion operators

bounding_box() defaulted noexcept
Default constructor. Values are not initialized.
bounding_box(const bounding_box&) defaulted constexpr noexcept
Copy constructor.
bounding_box(const vector_type& cen, const vector_type& ext) constexpr noexcept
Constructs a bounding box from center and extent values.
bounding_box(const vector_type& cen, scalar_type ext_x, scalar_type ext_y, scalar_type ext_z) constexpr noexcept
Constructs a bounding box from center and extent values.
bounding_box(const vector_type& cen, scalar_type ext) constexpr noexcept
Constructs a uniformly-sized bounding box.
bounding_box(const vector_type& ext) explicit constexpr noexcept
Constructs a bounding box at the origin.
bounding_box(scalar_type cen_x, scalar_type cen_y, scalar_type cen_z, const vector_type& ext) constexpr noexcept
Constructs a bounding box from center and extent values.
bounding_box(scalar_type cen_x, scalar_type cen_y, scalar_type cen_z, scalar_type ext_x, scalar_type ext_y, scalar_type ext_z) constexpr noexcept
Constructs a bounding box from center and extent values.
bounding_box(scalar_type ext) explicit constexpr noexcept
Constructs a uniformly-sized bounding box at the origin.
template <typename S>
bounding_box(const bounding_box<S>& bb) explicit constexpr noexcept
Converting constructor.
template <typename T>
bounding_box(const T& obj) constexpr noexcept
Constructs a bounding box from an implicitly bit-castable type.
bounding_box(const vector_type* begin, const vector_type* end) explicit constexpr noexcept
Constructs a bounding box fitting a range of points.
bounding_box(const vector_type* points, size_t count) explicit constexpr noexcept
Constructs a bounding box fitting a range of points.
template <size_t N>
bounding_box(const vector_type(&points)[N]) explicit constexpr noexcept
Constructs a bounding box fitting an array of points.
template <size_t N>
bounding_box(const span<vector_type, N>& vals) explicit constexpr noexcept
Constructs a bounding box fitting an array of points.
template <size_t N>
bounding_box(const const_span<vector_type, N>& vals) explicit constexpr noexcept
Constructs a bounding box fitting an array of points.
bounding_box(const oriented_bounding_box<scalar_type>& obb) explicit constexpr noexcept
Constructs a bounding box completely containing an oriented bounding-box.
bounding_box(const bounding_sphere<scalar_type>& bs) explicit constexpr noexcept
Constructs a bounding box completely containing a bounding sphere.

Public functions

auto operator=(const bounding_box&) -> bounding_box& defaulted constexpr noexcept
Copy-assigment operator.

Public variables

vector_type center
The center of the box.
vector_type extents
The half-lengths of box (i.e. distances from the center to the sides).

Appending

auto append(const vector_type& pt) -> bounding_box& constexpr noexcept
Adds a point to the bounding box (in-place), expanding the bounded region to contain it if necessary.
template <typename... T>
auto append(const vector_type& pt1, const vector_type& pt2, const T&... pts) -> bounding_box& constexpr noexcept
Adds two or more points to the bounding box (in-place), expanding the bounded region to contain them if necessary.
auto append(const bounding_box& bb) -> bounding_box& constexpr noexcept
Adds another box to the bounding box (in-place), expanding the bounded region to contain it if necessary.
auto append(const line_segment<scalar_type>& seg) -> bounding_box& constexpr noexcept
Adds a line segment to the bounding box (in-place), expanding the bounded region to contain it if necessary.
auto append(const triangle<scalar_type>& tri) -> bounding_box& constexpr noexcept
Adds a triangle to the bounding box (in-place), expanding the bounded region to contain it if necessary.

Collision detection

static auto contains(const bounding_box& bb, const vector_type& point) -> bool constexpr noexcept
Returns true if a bounding box contains a point.
static auto contains(const bounding_box& bb, const vector_type& start, const vector_type& end) -> bool constexpr noexcept
Returns true if a bounding box contains a line segment.
static auto contains(const bounding_box& bb, const line_segment<scalar_type>& seg) -> bool constexpr noexcept
Returns true if a bounding box contains a line segment.
static auto contains(const bounding_box& bb, const vector_type& p0, const vector_type& p1, const vector_type& p2) -> bool constexpr noexcept
Returns true if a bounding box contains a triangle.
static auto contains(const bounding_box& bb, const triangle<scalar_type>& tri) -> bool constexpr noexcept
Returns true if a bounding box contains a triangle.
static auto contains(const bounding_box& bb, const bounding_sphere<scalar_type>& bs) -> bool constexpr noexcept
Returns true if a bounding box contains all the points of a bounding sphere.
static auto contains(const bounding_box& outer, const bounding_box& inner) -> bool constexpr noexcept
Returns true if a bounding box contains all the points of another bounding box.
static auto contains(const bounding_box& bb, const oriented_bounding_box<scalar_type>& obb) -> bool constexpr noexcept
Returns true if an axis-aligned bounding box contains all the points of an oriented bounding box.
static auto intersects(const bounding_box& bb, const vector_type& start, const vector_type& end) -> bool constexpr noexcept
Returns true if a bounding box intersects a line segment.
static auto intersects(const bounding_box& bb, const line_segment<scalar_type>& seg) -> bool constexpr noexcept
Returns true if a bounding box intersects a line segment.
static auto intersects(const bounding_box& bb, const plane<scalar_type>& p) -> bool constexpr noexcept
Returns true if a bounding box intersects a plane.
static auto intersects(const bounding_box& bb, const vector_type& p0, const vector_type& p1, const vector_type& p2) -> bool constexpr noexcept
Returns true if a bounding box intersects a triangle.
static auto intersects(const bounding_box& bb, const triangle<scalar_type>& tri) -> bool constexpr noexcept
Returns true if a bounding box intersects a triangle.
static auto intersects(const bounding_box& bb, const bounding_sphere<scalar_type>& bs) -> bool constexpr noexcept
Returns true if a bounding box intersects a bounding sphere.
static auto intersects(const bounding_box& bb1, const bounding_box& bb2) -> bool constexpr noexcept
Returns true if two bounding boxes intersect.
static auto intersects(const bounding_box& aabb, const oriented_bounding_box<scalar_type>& obb) -> bool constexpr noexcept
Returns true if an axis-aligned bounding box intersects an oriented bounding box.
auto collision_tester() const -> muu::collision_tester<bounding_box> constexpr noexcept
Creates an #muu::collision_tester for this bounding box.
auto contains(const vector_type& point) const -> bool constexpr noexcept
Returns true if the bounding box contains a point.
auto contains(const vector_type* begin, const vector_type* end) -> bool constexpr noexcept
Returns true if the bounding box contains all the points in an arbitrary collection.
auto contains(const line_segment<scalar_type>& seg) const -> bool constexpr noexcept
Returns true if the bounding box contains a line segment.
auto contains(const triangle<scalar_type>& tri) const -> bool constexpr noexcept
Returns true if the bounding box contains a triangle.
auto contains(const bounding_sphere<scalar_type>& bs) const -> bool constexpr noexcept
Returns true if a bounding box contains all the points of a bounding sphere.
auto contains(const bounding_box& bb) const -> bool constexpr noexcept
Returns true if a bounding box contains all the points of another bounding box.
auto contains(const oriented_bounding_box<scalar_type>& obb) const -> bool constexpr noexcept
Returns true if an axis-aligned bounding box contains all the points of an oriented bounding box.
auto intersects(const line_segment<scalar_type>& seg) const -> bool constexpr noexcept
Returns true if the bounding box intersects a line segment.
auto intersects(const plane<scalar_type>& p) const -> bool constexpr noexcept
Returns true if the bounding box intersects a plane.
auto intersects(const triangle<scalar_type>& tri) const -> bool constexpr noexcept
Returns true if the bounding box intersects a triangle.
auto intersects(const bounding_sphere<scalar_type>& bs) const -> bool constexpr noexcept
Returns true if the bounding box intersects a bounding sphere.
auto intersects(const bounding_box& bb) const -> bool constexpr noexcept
Returns true if two bounding boxes intersect.
auto intersects(const oriented_bounding_box<scalar_type>& obb) const -> bool constexpr noexcept
Returns true if the axis-aligned bounding box intersects an oriented bounding box.

Corners

template <box_corner Corner>
static auto corner(const bounding_box& bb) -> vector_type constexpr noexcept
Returns a specific corner of a bounding box.
static auto corner(const bounding_box& bb, box_corner which) -> vector_type constexpr noexcept
Returns a specific corner of a bounding box.
static auto max_corner(const bounding_box& bb) -> vector_type constexpr noexcept
Returns the 'max' corner of a bounding box.
static auto min_corner(const bounding_box& bb) -> vector_type constexpr noexcept
Returns the 'min' corner of a bounding box.
template <box_corner Corner>
auto corner() const -> vector_type constexpr noexcept
Returns a specific corner of the bounding box.
auto corner(box_corner which) const -> vector_type constexpr noexcept
Returns a specific corner of the bounding box.
auto max_corner() const -> vector_type constexpr noexcept
Returns the 'max' corner of the bounding box.
auto min_corner() const -> vector_type constexpr noexcept
Returns the 'min' corner of the bounding box.

Equality (approximate)

static auto approx_empty(const bounding_box& bb, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a bounding box has approximately zero volume.
template <typename T>
static auto approx_equal(const bounding_box& bb1, const bounding_box<T>& bb2, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) -> bool constexpr noexcept
Returns true if two bounding boxes are approximately equal.
static auto approx_zero(const bounding_box& bb, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if all the scalar components in a bounding box are approximately equal to zero.
auto approx_empty(scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if the bounding box has approximately zero volume.
template <typename T>
auto approx_equal(const bounding_box<T>& bb, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) const -> bool constexpr noexcept
Returns true if the bounding box is approximately equal to another.
auto approx_zero(scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if all the scalar components in the bounding box are approximately equal to zero.

Equality (exact)

static auto degenerate(const bounding_box& bb) -> bool constexpr noexcept
Returns true if a box is degenerate (i.e. any of its extents are less than or equal to zero).
static auto empty(const bounding_box& bb) -> bool constexpr noexcept
Returns true if a bounding box has exactly zero volume.
static auto infinity_or_nan(const bounding_box& bb) -> bool constexpr noexcept
Returns true if any of the scalar components of a bounding box are infinity or NaN.
static auto zero(const bounding_box& bb) -> bool constexpr noexcept
Returns true if all the scalar components of a bounding box are exactly zero.
auto degenerate() const -> bool constexpr noexcept
Returns true if the box is degenerate (i.e. any of its extents are less than or equal to zero).
auto empty() const -> bool constexpr noexcept
Returns true if the bounding box has exactly zero volume.
auto infinity_or_nan() const -> bool constexpr noexcept
Returns true if any of the scalar components of the bounding box are infinity or NaN.
auto zero() const -> bool constexpr noexcept
Returns true if all the scalar components of the bounding box are exactly zero.
template <typename T>
auto operator!=(const bounding_box& lhs, const bounding_box<T>& rhs) -> bool constexpr noexcept
Returns true if two bounding boxes are not exactly equal.
template <typename T>
auto operator==(const bounding_box& lhs, const bounding_box<T>& rhs) -> bool constexpr noexcept
Returns true if two bounding boxes are exactly equal.

Geometric properties

auto density(scalar_type mass) const -> scalar_type constexpr noexcept
Calculates the density of this box if it had a given mass.
auto depth() const -> scalar_type constexpr noexcept
Returns the depth of the box (z-axis).
auto diagonal() const -> scalar_type constexpr noexcept
Calculates the length of the line connecting the min and max points.
auto height() const -> scalar_type constexpr noexcept
Returns the height of the box (y-axis).
auto longest_extent() -> scalar_type& constexpr noexcept
Returns the longest of the box's three extents.
auto longest_extent() const -> constscalar_type& constexpr noexcept
Returns the longest of the box's three extents (const overload).
auto longest_side() const -> scalar_type constexpr noexcept
Returns the length of the longest of the box's three sides.
auto mass(scalar_type density) const -> scalar_type constexpr noexcept
Calculates the mass of this box if it had a given density.
auto shortest_extent() -> scalar_type& constexpr noexcept
Returns the shortest of the box's three extents.
auto shortest_extent() const -> constscalar_type& constexpr noexcept
Returns the shortest of the box's three extents (const overload).
auto shortest_side() const -> scalar_type constexpr noexcept
Returns the length of the shortest of the box's three sides.
auto volume() const -> scalar_type constexpr noexcept
Calculates the volume of this bounding box.
auto width() const -> scalar_type constexpr noexcept
Returns the width of the box (x-axis).

Point queries

auto closest_point(const vector_type& point) const -> vector_type constexpr noexcept
Gets point contained by the bounding box closest to another arbitrary point.

Scalar accessors

auto data() -> scalar_type* constexpr noexcept
Returns a pointer to the first scalar component in the bounding box.
auto data() const -> constscalar_type* constexpr noexcept
Returns a pointer to the first scalar component in the bounding box.

Scaling

static auto scale(const bounding_box& bb, const vector_type& scale_) -> bounding_box constexpr noexcept
Scales a bounding box.
auto scale(const vector_type& scale_) -> bounding_box& constexpr noexcept
Scales the bounding box (in-place).

Transformation

static auto transform(const bounding_box& bb, const matrix<scalar_type, 4, 4>& tx) -> bounding_box constexpr noexcept
Transforms an axis-aligned bounding box from one coordinate space to another.
auto transform(const matrix<scalar_type, 4, 4>& tx) -> bounding_box& constexpr noexcept
Transforms the axis-aligned bounding box from one coordinate space to another (in-place).

Translation

static auto translate(const bounding_box& bb, const vector_type& offset) -> bounding_box constexpr noexcept
Translates a bounding box.
auto translate(const vector_type& offset) -> bounding_box& constexpr noexcept
Translates the bounding box (in-place).

Friends

template <typename Char, typename Traits>
auto operator<<(std::basic_ostream<Char, Traits>& os, const bounding_box& bb) -> std::basic_ostream<Char, Traits>&
Writes a bounding box out to a text stream.

Function documentation

template <typename Scalar>
muu::bounding_box::bounding_box(const vector_type& cen, const vector_type& ext) constexpr noexcept

Constructs a bounding box from center and extent values.

Parameters
cen The center point.
ext The extents.

template <typename Scalar>
muu::bounding_box::bounding_box(const vector_type& cen, scalar_type ext_x, scalar_type ext_y, scalar_type ext_z) constexpr noexcept

Constructs a bounding box from center and extent values.

Parameters
cen The center point.
ext_x The length of the X extent.
ext_y The length of the Y extent.
ext_z The length of the Z extent.

template <typename Scalar>
muu::bounding_box::bounding_box(const vector_type& cen, scalar_type ext) constexpr noexcept

Constructs a uniformly-sized bounding box.

Parameters
cen The center point.
ext The length of all three extents.

template <typename Scalar>
muu::bounding_box::bounding_box(const vector_type& ext) explicit constexpr noexcept

Constructs a bounding box at the origin.

Parameters
ext The extents.

template <typename Scalar>
muu::bounding_box::bounding_box(scalar_type cen_x, scalar_type cen_y, scalar_type cen_z, const vector_type& ext) constexpr noexcept

Constructs a bounding box from center and extent values.

Parameters
cen_x The X component of the center point.
cen_y The Y component of the center point.
cen_z The Z component of the center point.
ext The extents.

template <typename Scalar>
muu::bounding_box::bounding_box(scalar_type cen_x, scalar_type cen_y, scalar_type cen_z, scalar_type ext_x, scalar_type ext_y, scalar_type ext_z) constexpr noexcept

Constructs a bounding box from center and extent values.

Parameters
cen_x The X component of the center point.
cen_y The Y component of the center point.
cen_z The Z component of the center point.
ext_x The length of the X extent.
ext_y The length of the Y extent.
ext_z The length of the Z extent.

template <typename Scalar>
muu::bounding_box::bounding_box(scalar_type ext) explicit constexpr noexcept

Constructs a uniformly-sized bounding box at the origin.

Parameters
ext The length of all three extents.

template <typename Scalar>
template <typename T>
muu::bounding_box::bounding_box(const T& obj) constexpr noexcept

Constructs a bounding box from an implicitly bit-castable type.

Template parameters
T A bit-castable type.

template <typename Scalar>
bounding_box& muu::bounding_box::append(const vector_type& pt) constexpr noexcept

Adds a point to the bounding box (in-place), expanding the bounded region to contain it if necessary.

Parameters
pt The point being added to the box's volume.
Returns A reference to the box.

template <typename Scalar>
template <typename... T>
bounding_box& muu::bounding_box::append(const vector_type& pt1, const vector_type& pt2, const T&... pts) constexpr noexcept

Adds two or more points to the bounding box (in-place), expanding the bounded region to contain them if necessary.

Parameters
pt1 The first point being added to the box's volume.
pt2 The second point being added to the box's volume.
pts The remaining points being added to the box's volume.
Returns A reference to the box.

template <typename Scalar>
bounding_box& muu::bounding_box::append(const bounding_box& bb) constexpr noexcept

Adds another box to the bounding box (in-place), expanding the bounded region to contain it if necessary.

Parameters
bb The bounding box being added to the box's volume.
Returns A reference to the box.

template <typename Scalar>
bounding_box& muu::bounding_box::append(const line_segment<scalar_type>& seg) constexpr noexcept

Adds a line segment to the bounding box (in-place), expanding the bounded region to contain it if necessary.

Parameters
seg The line segment being added to the box's volume.
Returns A reference to the box.

template <typename Scalar>
bounding_box& muu::bounding_box::append(const triangle<scalar_type>& tri) constexpr noexcept

Adds a triangle to the bounding box (in-place), expanding the bounded region to contain it if necessary.

Parameters
tri The triangle being added to the box's volume.
Returns A reference to the box.

template <typename Scalar>
static bool muu::bounding_box::empty(const bounding_box& bb) constexpr noexcept

Returns true if a bounding box has exactly zero volume.

template <typename Scalar>
static bool muu::bounding_box::zero(const bounding_box& bb) constexpr noexcept

Returns true if all the scalar components of a bounding box are exactly zero.

template <typename Scalar>
bool muu::bounding_box::empty() const constexpr noexcept

Returns true if the bounding box has exactly zero volume.

template <typename Scalar>
bool muu::bounding_box::zero() const constexpr noexcept

Returns true if all the scalar components of the bounding box are exactly zero.

template <typename Scalar>
template <typename T>
bool muu::bounding_box::operator!=(const bounding_box& lhs, const bounding_box<T>& rhs) constexpr noexcept

Returns true if two bounding boxes are not exactly equal.

template <typename Scalar>
template <typename T>
bool muu::bounding_box::operator==(const bounding_box& lhs, const bounding_box<T>& rhs) constexpr noexcept

Returns true if two bounding boxes are exactly equal.

template <typename Scalar>
static bounding_box muu::bounding_box::scale(const bounding_box& bb, const vector_type& scale_) constexpr noexcept

Scales a bounding box.

Parameters
bb The bounding box to scale.
scale_ The amount to scale the box extents by on each axis.
Returns A copy of the input box scaled by the given amounts.

template <typename Scalar>
bounding_box& muu::bounding_box::scale(const vector_type& scale_) constexpr noexcept

Scales the bounding box (in-place).

Parameters
scale_ The amount to scale the box extents by on each axis.
Returns A reference to the box.

template <typename Scalar>
static bounding_box muu::bounding_box::transform(const bounding_box& bb, const matrix<scalar_type, 4, 4>& tx) constexpr noexcept

Transforms an axis-aligned bounding box from one coordinate space to another.

Parameters
bb The bounding box to transform.
tx The transform to apply.
Returns Returns an axis-aligned bounding box containing all the points of the input bounding box after being transformed.

template <typename Scalar>
bounding_box& muu::bounding_box::transform(const matrix<scalar_type, 4, 4>& tx) constexpr noexcept

Transforms the axis-aligned bounding box from one coordinate space to another (in-place).

Parameters
tx The transform to apply.
Returns A reference to the box.

template <typename Scalar>
static bounding_box muu::bounding_box::translate(const bounding_box& bb, const vector_type& offset) constexpr noexcept

Translates a bounding box.

Parameters
bb The bounding box to translate.
offset An offset to add to the box's center position.
Returns A copy of the input box translated by the given offset.

template <typename Scalar>
bounding_box& muu::bounding_box::translate(const vector_type& offset) constexpr noexcept

Translates the bounding box (in-place).

Parameters
offset An offset to add to the box's center position.
Returns A reference to the box_.