#include <muu/bounding_box.h>
template <typename Scalar>
bounding_box struct
An axis-aligned bounding box.
Template parameters | |
---|---|
Scalar | The bounding box's scalar component type. Must be a floating-point type. |
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_static auto corner(const bounding_
corner Corner> 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_auto corner() const -> vector_
corner Corner> 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
template <typename T>
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
template <typename... T>
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
template <typename T>
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
template <typename T>
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_. |