2#ifndef LIBSBX_MATH_VOLUME_HPP_
3#define LIBSBX_MATH_VOLUME_HPP_
8#include <libsbx/math/vector3.hpp>
9#include <libsbx/math/matrix4x4.hpp>
18 using value_type = Type;
28 auto min =
math::vector3{std::numeric_limits<std::float_t>::max()};
29 auto max =
math::vector3{std::numeric_limits<std::float_t>::lowest()};
31 for (
const auto& corner :
volume.corners()) {
49 return (_min + _max) / 2.0f;
52 auto corners()
const noexcept -> std::array<math::vector3, 8u> {
53 return std::array<math::vector3, 8u>{
65 auto contains(
const vector_type& point)
const noexcept ->
bool {
66 return point.x() >= _min.x() && point.x() <= _max.x() && point.y() >= _min.y() && point.y() <= _max.y() && point.z() >= _min.z() && point.z() <= _max.z();
69 auto contains(
const basic_volume& other)
const noexcept ->
bool {
70 return _min.x() <= other.min().x() && _min.y() <= other.min().y() && _min.z() <= other.min().z() && _max.x() >= other.max().x() && _max.y() >= other.max().y() && _max.z() >= other.max().z();
73 auto intersects(
const basic_volume& other)
const noexcept ->
bool {
74 return _min.x() <= other.max().x() && _max.x() >= other.min().x() && _min.y() <= other.max().y() && _max.y() >= other.min().y() && _min.z() <= other.max().z() && _max.z() >= other.min().z();
81 auto diagonal_length()
const noexcept -> value_type {
82 return extend().length();
85 auto is_empty()
const noexcept ->
bool {
86 return _min.x() >= _max.x() || _min.y() >= _max.y() || _min.z() >= _max.z();
89 auto include(
const basic_volume& other)
noexcept ->
void {
102 return (a.min().x() <= b.max().x() && a.max().x() >= b.min().x()) && (a.min().y() <= b.max().y() && a.max().y() >= b.min().y()) && (a.min().z() <= b.max().z() && a.max().z() >= b.min().z());
105 template<std::ranges::input_range Range,
typename Projection = std::
identity>
106 requires (std::convertible_to<std::invoke_result_t<Projection, std::ranges::range_reference_t<Range>>,
vector_type>)
107 static auto construct(Range&& range, Projection projection = {}) ->
basic_volume {
108 auto iterator = std::ranges::begin(range);
109 const auto end = std::ranges::end(range);
111 if (iterator == end) {
115 auto first_point = std::invoke(projection, *iterator);
117 auto min = first_point;
118 auto max = first_point;
122 for (; iterator != end; ++iterator) {
123 const auto point = std::invoke(projection, *iterator);
Definition: matrix4x4.hpp:26
Definition: vector4.hpp:24
static constexpr auto min(const basic_vector &vector) noexcept -> value_type
Returns the minimum component of a vector.
Definition: vector.ipp:20
static constexpr auto max(const basic_vector &vector) noexcept -> value_type
Returns the maximum component of a vector.
Definition: vector.ipp:45
Definition: volume.hpp:14
Core numeric concepts and type traits.