#include <muu/oriented_bounding_box.h>
template <typename Scalar>
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_static auto corner(const oriented_
corner Corner> 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_auto corner() const -> vector_
corner Corner> 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
template <typename T>
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
template <typename T>
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
template <typename T>
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_. |