template <typename Scalar>
muu::oriented_bounding_box struct

An oriented bounding box.

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

Public types

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

Constructors, destructors, conversion operators

oriented_bounding_box() defaulted noexcept
Default constructor. Values are not initialized.
oriented_bounding_box(const oriented_bounding_box&) defaulted constexpr noexcept
Copy constructor.
oriented_bounding_box(const vector_type& cen, const vector_type& ext, const axes_type& rot = axes_constants::identity) constexpr noexcept
Constructs a oriented bounding box from center, extents and axes values.
oriented_bounding_box(const vector_type& cen, scalar_type ext_x, scalar_type ext_y, scalar_type ext_z, const axes_type& rot = axes_constants::identity) constexpr noexcept
Constructs a oriented bounding box from center, extents and axes values.
oriented_bounding_box(const vector_type& cen, scalar_type ext, const axes_type& rot = axes_constants::identity) constexpr noexcept
Constructs a uniformly-sized oriented bounding box.
oriented_bounding_box(const vector_type& ext, const axes_type& rot = axes_constants::identity) explicit constexpr noexcept
Constructs an oriented bounding box at the origin.
oriented_bounding_box(scalar_type cen_x, scalar_type cen_y, scalar_type cen_z, const vector_type& ext, const axes_type& rot = axes_constants::identity) constexpr noexcept
Constructs an oriented bounding box from center and extent values.
oriented_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, const axes_type& rot = axes_constants::identity) constexpr noexcept
Constructs an oriented bounding box from center and extent values.
oriented_bounding_box(scalar_type ext, const axes_type& rot = axes_constants::identity) explicit constexpr noexcept
Constructs a uniformly-sized oriented bounding box at the origin.
template <typename S>
oriented_bounding_box(const oriented_bounding_box<S>& bb) explicit constexpr noexcept
Converting constructor.
template <typename T>
oriented_bounding_box(const T& obj) constexpr noexcept
Constructs a oriented bounding box from an implicitly bit-castable type.

Public functions

auto operator=(const oriented_bounding_box&) -> oriented_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).
axes_type axes
The axes of the box's orientation.

Collision detection

static auto contains(const oriented_bounding_box& bb, const vector_type& point) -> bool constexpr noexcept
Returns true if an oriented bounding box contains a point.
static auto contains(const oriented_bounding_box& bb, const vector_type& start, const vector_type& end) -> bool constexpr noexcept
Returns true if an oriented bounding box contains a line segment.
static auto contains(const oriented_bounding_box& bb, const line_segment<scalar_type>& seg) -> bool constexpr noexcept
Returns true if an oriented bounding box contains a line segment.
static auto contains(const oriented_bounding_box& bb, const vector_type& p0, const vector_type& p1, const vector_type& p2) -> bool constexpr noexcept
Returns true if an oriented bounding contains a triangle.
static auto contains(const oriented_bounding_box& bb, const triangle<scalar_type>& tri) -> bool constexpr noexcept
Returns true if an oriented bounding contains a triangle.
static auto intersects(const oriented_bounding_box& bb, const vector_type& p0, const vector_type& p1, const vector_type& p2) -> bool constexpr noexcept
Returns true if an oriented bounding intersects a triangle.
static auto intersects(const oriented_bounding_box& bb, const triangle<scalar_type>& tri) -> bool constexpr noexcept
Returns true if an oriented bounding intersects a triangle.
static auto intersects(const oriented_bounding_box& bb, const bounding_sphere<scalar_type>& bs) -> bool constexpr noexcept
Returns true if an oriented bounding box intersects a bounding sphere.
static auto intersects(const oriented_bounding_box& obb, const bounding_box<scalar_type>& aabb) -> bool constexpr noexcept
Returns true if an oriented bounding box intersects an axis-aligned bounding_box.
static auto intersects(const oriented_bounding_box& bb1, const oriented_bounding_box& bb2) -> bool constexpr noexcept
Returns true if two oriented bounding boxes intersect.
auto contains(const vector_type& point) const -> bool constexpr noexcept
Returns true if the oriented bounding box contains a point.
auto contains(const vector_type* begin, const vector_type* end) -> bool constexpr noexcept
Returns true if the oriented 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 oriented bounding box contains a line segment.
auto contains(const triangle<scalar_type>& tri) const -> bool constexpr noexcept
Returns true if the oriented bounding contains a triangle.
auto intersects(const triangle<scalar_type>& tri) const -> bool constexpr noexcept
Returns true if the oriented bounding intersects a triangle.
auto intersects(const bounding_sphere<scalar_type>& bs) const -> bool constexpr noexcept
Returns true if the oriented bounding box intersects a bounding sphere.
auto intersects(const bounding_box<scalar_type>& aabb) const -> bool constexpr noexcept
Returns true if the oriented bounding box intersects an axis-aligned bounding_box.
auto intersects(const oriented_bounding_box& bb) const -> bool constexpr noexcept
Returns true if two oriented bounding boxes intersect.

Corners

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

Equality (approximate)

static auto approx_empty(const oriented_bounding_box& bb, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if an oriented bounding box has approximately zero volume.
template <typename T>
static auto approx_equal(const oriented_bounding_box& bb1, const oriented_bounding_box<T>& bb2, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) -> bool constexpr noexcept
Returns true if two oriented bounding boxes are approximately equal.
static auto approx_zero(const oriented_bounding_box& bb, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if all the scalar components in an oriented 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 oriented bounding box has approximately zero volume.
template <typename T>
auto approx_equal(const oriented_bounding_box<T>& bb, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) const -> bool constexpr noexcept
Returns true if the oriented 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 oriented bounding box are approximately equal to zero.

Equality (exact)

static auto degenerate(const oriented_bounding_box& bb) -> bool constexpr noexcept
Returns true if the box is degenerate (i.e. any of its extents are less than or equal to zero).
static auto empty(const oriented_bounding_box& bb) -> bool constexpr noexcept
Returns true if an oriented bounding box has exactly zero volume.
static auto infinity_or_nan(const oriented_bounding_box& bb) -> bool constexpr noexcept
Returns true if any of the scalar components of an oriented bounding box are infinity or NaN.
static auto zero(const oriented_bounding_box& bb) -> bool constexpr noexcept
Returns true if all the scalar components of an oriented 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 oriented bounding box has exactly zero volume.
auto infinity_or_nan() const -> bool constexpr noexcept
Returns true if any of the scalar components of the oriented bounding box are infinity or NaN.
auto zero() const -> bool constexpr noexcept
Returns true if all the scalar components of the oriented bounding box are exactly zero.
template <typename T>
auto operator!=(const oriented_bounding_box& lhs, const oriented_bounding_box<T>& rhs) -> bool constexpr noexcept
Returns true if two oriented bounding boxes are not exactly equal.
template <typename T>
auto operator==(const oriented_bounding_box& lhs, const oriented_bounding_box<T>& rhs) -> bool constexpr noexcept
Returns true if two oriented 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 oriented_bounding_box& bb, const vector_type& scale_) -> oriented_bounding_box constexpr noexcept
Scales an oriented bounding box.
auto scale(const vector_type& scale_) -> oriented_bounding_box& constexpr noexcept
Scales the oriented bounding box (in-place).

Transformation

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

Translation

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

Function documentation

template <typename Scalar>
muu::oriented_bounding_box::oriented_bounding_box(const vector_type& cen, const vector_type& ext, const axes_type& rot = axes_constants::identity) constexpr noexcept

Constructs a oriented bounding box from center, extents and axes values.

Parameters
cen The center point.
ext The extents.
rot The rotation axes.

template <typename Scalar>
muu::oriented_bounding_box::oriented_bounding_box(const vector_type& cen, scalar_type ext_x, scalar_type ext_y, scalar_type ext_z, const axes_type& rot = axes_constants::identity) constexpr noexcept

Constructs a oriented bounding box from center, extents and axes 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.
rot The rotation axes.

template <typename Scalar>
muu::oriented_bounding_box::oriented_bounding_box(const vector_type& cen, scalar_type ext, const axes_type& rot = axes_constants::identity) constexpr noexcept

Constructs a uniformly-sized oriented bounding box.

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

template <typename Scalar>
muu::oriented_bounding_box::oriented_bounding_box(const vector_type& ext, const axes_type& rot = axes_constants::identity) explicit constexpr noexcept

Constructs an oriented bounding box at the origin.

Parameters
ext The extents.
rot The rotation axes.

template <typename Scalar>
muu::oriented_bounding_box::oriented_bounding_box(scalar_type cen_x, scalar_type cen_y, scalar_type cen_z, const vector_type& ext, const axes_type& rot = axes_constants::identity) constexpr noexcept

Constructs an oriented 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.
rot The rotation axes.

template <typename Scalar>
muu::oriented_bounding_box::oriented_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, const axes_type& rot = axes_constants::identity) constexpr noexcept

Constructs an oriented 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.
rot The rotation axes.

template <typename Scalar>
muu::oriented_bounding_box::oriented_bounding_box(scalar_type ext, const axes_type& rot = axes_constants::identity) explicit constexpr noexcept

Constructs a uniformly-sized oriented bounding box at the origin.

Parameters
ext The length of all three extents.
rot The rotation axes.

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

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

Template parameters
T A bit-castable type.

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

Returns true if an oriented bounding box has exactly zero volume.

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

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

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

Returns true if the oriented bounding box has exactly zero volume.

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

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

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

Returns true if two oriented bounding boxes are not exactly equal.

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

Returns true if two oriented bounding boxes are exactly equal.

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

Scales an oriented bounding box.

Parameters
bb The oriented 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>
oriented_bounding_box& muu::oriented_bounding_box::scale(const vector_type& scale_) constexpr noexcept

Scales the oriented 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 oriented_bounding_box muu::oriented_bounding_box::transform(const oriented_bounding_box& bb, const matrix<scalar_type, 4, 4>& tx) constexpr noexcept

Transforms an oriented bounding box from one coordinate space to another.

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

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

Transforms the oriented 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 oriented_bounding_box muu::oriented_bounding_box::translate(const oriented_bounding_box& bb, const vector_type& offset) constexpr noexcept

Translates an oriented bounding box.

Parameters
bb The oriented 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>
oriented_bounding_box& muu::oriented_bounding_box::translate(const vector_type& offset) constexpr noexcept

Translates the oriented bounding box (in-place).

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

Variable documentation

template <typename Scalar>
axes_type muu::oriented_bounding_box::axes

The axes of the box's orientation.