8#include "../numeric_array.hpp"
22 static_assert(D == 2 || D == 3,
"Only 2D or 3D extents are supported");
26 constexpr extent &operator=(
extent const &)
noexcept =
default;
27 constexpr extent &operator=(
extent &&)
noexcept =
default;
32 requires(E < D) [[nodiscard]]
constexpr extent(
extent<E> const &other) noexcept : _v(
static_cast<f32x4>(other))
39 [[nodiscard]]
constexpr explicit operator f32x4() const noexcept
46 [[nodiscard]]
constexpr explicit extent(
f32x4 const &other) noexcept : _v(other)
53 [[nodiscard]]
constexpr extent() noexcept : _v(0.0f, 0.0f, 0.0f, 0.0f) {}
74 [[nodiscard]]
constexpr float &
width() noexcept
85 [[nodiscard]]
constexpr float &
height() noexcept
96 [[nodiscard]]
constexpr float &
depth() noexcept requires(D == 3)
107 [[nodiscard]]
constexpr float const &
width() const noexcept
118 [[nodiscard]]
constexpr float const &
height() const noexcept
129 [[nodiscard]]
constexpr float const &
depth() const noexcept requires(D == 3)
141 tt_axiom(lhs.is_valid() && rhs.is_valid());
142 return extent{lhs._v + rhs._v};
152 tt_axiom(lhs.is_valid() && rhs.is_valid());
153 return extent{lhs._v - rhs._v};
163 tt_axiom(lhs.is_valid());
164 return extent{lhs._v * rhs};
174 tt_axiom(rhs.is_valid());
175 return extent{lhs * rhs._v};
185 tt_axiom(lhs.is_valid() && rhs.is_valid());
186 return lhs._v == rhs._v;
195 tt_axiom(rhs.is_valid());
196 return squared_hypot<element_mask>(rhs._v);
203 [[nodiscard]]
constexpr friend float hypot(
extent const &rhs)
noexcept
205 tt_axiom(rhs.is_valid());
206 return hypot<element_mask>(rhs._v);
215 tt_axiom(rhs.is_valid());
216 return rcp_hypot<element_mask>(rhs._v);
225 tt_axiom(rhs.is_valid());
226 return extent{normalize<element_mask>(rhs._v)};
232 [[nodiscard]]
constexpr bool is_valid() const noexcept
234 return _v.w() == 0.0f && (D == 3 || _v.z() == 0.0f);
240 static constexpr size_t element_mask = (1_uz << D) - 1;
245using extent2 = geo::extent<2>;
246using extent3 = geo::extent<3>;
A high-level geometric extent.
Definition extent.hpp:20
constexpr float const & height() const noexcept
Access the y-as-height element from the extent.
Definition extent.hpp:118
constexpr float const & width() const noexcept
Access the x-as-width element from the extent.
Definition extent.hpp:107
constexpr float & width() noexcept
Access the x-as-width element from the extent.
Definition extent.hpp:74
constexpr friend extent operator*(float const &lhs, extent const &rhs) noexcept
Scale the extent by a scaler.
Definition extent.hpp:172
constexpr bool is_valid() const noexcept
Check if the extent is valid.
Definition extent.hpp:232
constexpr friend float squared_hypot(extent const &rhs) noexcept
Get the squared length of the extent.
Definition extent.hpp:193
constexpr friend extent operator-(extent const &lhs, extent const &rhs) noexcept
Subtract two extents from each other.
Definition extent.hpp:150
constexpr friend extent operator*(extent const &lhs, float const &rhs) noexcept
Scale the extent by a scaler.
Definition extent.hpp:161
constexpr friend float rcp_hypot(extent const &rhs) noexcept
Get the length of the extent.
Definition extent.hpp:213
constexpr friend extent normalize(extent const &rhs) noexcept
Normalize a extent to a unit extent.
Definition extent.hpp:223
constexpr extent(float width, float height, float depth=0.0f) noexcept
Construct a 3D extent from x, y and z elements.
Definition extent.hpp:66
constexpr extent(extent< E > const &other) noexcept
Construct a extent from a lower dimension extent.
Definition extent.hpp:32
constexpr extent(float width, float height) noexcept
Construct a 2D extent from x and y elements.
Definition extent.hpp:59
constexpr float & depth() noexcept
Access the z-as-depth element from the extent.
Definition extent.hpp:96
constexpr friend float hypot(extent const &rhs) noexcept
Get the length of the extent.
Definition extent.hpp:203
constexpr float const & depth() const noexcept
Access the z-as-depth element from the extent.
Definition extent.hpp:129
constexpr float & height() noexcept
Access the y-as-height element from the extent.
Definition extent.hpp:85
constexpr extent(f32x4 const &other) noexcept
Construct a extent from a f32x4-numeric_array.
Definition extent.hpp:46
constexpr friend bool operator==(extent const &lhs, extent const &rhs) noexcept
Compare if two extents are equal.
Definition extent.hpp:183
constexpr extent() noexcept
Construct a empty extent / zero length.
Definition extent.hpp:53
constexpr friend extent operator+(extent const &lhs, extent const &rhs) noexcept
Add two extents from each other.
Definition extent.hpp:139