8#include "../rapid/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)
51 [[nodiscard]]
constexpr explicit operator bool () const noexcept
53 if constexpr (D == 2) {
54 return _v.x() != 0.0f or _v.y() != 0.0f;
55 }
else if constexpr (D == 3) {
56 return _v.x() != 0.0f or _v.y() != 0.0f or _v.z() != 0.0f;
63 [[nodiscard]]
constexpr explicit operator vector<E>() const noexcept requires(E >= D)
66 return vector<E>{
static_cast<f32x4
>(*this)};
71 [[nodiscard]]
constexpr extent() noexcept : _v(0.0f, 0.0f, 0.0f, 0.0f)
96 [[nodiscard]]
static constexpr extent infinity() noexcept requires(D == 2)
101 [[nodiscard]]
static constexpr extent infinity() noexcept requires(D == 3)
109 [[nodiscard]]
static constexpr extent large() noexcept requires(D == 2)
111 return extent{32767.0f, 32767.0f};
114 [[nodiscard]]
static constexpr extent large() noexcept requires(D == 3)
116 return extent{32767.0f, 32767.0f, 32767.0f};
119 [[nodiscard]]
static constexpr extent nan() noexcept requires(D == 2)
127 [[nodiscard]]
static constexpr extent nan() noexcept requires(D == 3)
142 [[nodiscard]]
constexpr float &
width() noexcept
153 [[nodiscard]]
constexpr float &
height() noexcept
164 [[nodiscard]]
constexpr float &
depth() noexcept requires(D == 3)
175 [[nodiscard]]
constexpr float const &
width() const noexcept
186 [[nodiscard]]
constexpr float const &
height() const noexcept
197 [[nodiscard]]
constexpr float const &
depth() const noexcept requires(D == 3)
202 [[nodiscard]]
constexpr vector<D> right() const noexcept
207 [[nodiscard]]
constexpr vector<D> up() const noexcept
209 return vector<D>{_v._0y00()};
212 constexpr extent &operator+=(
extent const &rhs)
noexcept
214 return *
this = *
this + rhs;
224 tt_axiom(lhs.is_valid() && rhs.is_valid());
225 return extent{lhs._v + rhs._v};
235 tt_axiom(lhs.is_valid() && rhs.is_valid());
236 return extent{lhs._v - rhs._v};
246 tt_axiom(lhs.is_valid());
247 return extent{lhs._v * rhs};
253 tt_axiom(lhs.is_valid());
254 tt_axiom(rhs.is_valid());
260 [[nodiscard]]
constexpr friend auto operator+(vector<E>
const &lhs,
extent const &rhs)
noexcept
262 tt_axiom(lhs.is_valid());
263 tt_axiom(rhs.is_valid());
265 return vector<
std::max(D, E)>{
static_cast<f32x4
>(lhs) +
static_cast<f32x4
>(rhs)};
275 tt_axiom(lhs.is_valid());
278 for (
size_t i = 0; i != D; ++i) {
279 r._v[i] = lhs._v[i] + rhs;
292 tt_axiom(rhs.is_valid());
293 return extent{lhs * rhs._v};
303 tt_axiom(lhs.is_valid() && rhs.is_valid());
304 return lhs._v == rhs._v;
311 return lhs.width() < rhs.width() && lhs.height() < rhs.height();
318 return lhs.width() < rhs.width() && lhs.height() < rhs.height() && lhs.depth() < rhs.depth();
325 return lhs.width() <= rhs.width() && lhs.height() <= rhs.height();
332 return lhs.width() <= rhs.width() && lhs.height() <= rhs.height() && lhs.depth() <= rhs.depth();
339 return lhs.width() > rhs.width() && lhs.height() > rhs.height();
346 return lhs.width() > rhs.width() && lhs.height() > rhs.height() && lhs.depth() > rhs.depth();
353 return lhs.width() >= rhs.width() && lhs.height() >= rhs.height();
360 return lhs.width() >= rhs.width() && lhs.height() >= rhs.height() && lhs.depth() >= rhs.depth();
369 tt_axiom(rhs.is_valid());
370 return squared_hypot<element_mask>(rhs._v);
377 [[nodiscard]]
constexpr friend float hypot(
extent const &rhs)
noexcept
379 tt_axiom(rhs.is_valid());
380 return hypot<element_mask>(rhs._v);
389 tt_axiom(rhs.is_valid());
390 return rcp_hypot<element_mask>(rhs._v);
399 tt_axiom(rhs.is_valid());
400 return extent{normalize<element_mask>(rhs._v)};
403 [[nodiscard]]
constexpr friend extent ceil(
extent const &rhs)
noexcept
405 tt_axiom(rhs.is_valid());
409 [[nodiscard]]
constexpr friend extent floor(
extent const &rhs)
noexcept
411 tt_axiom(rhs.is_valid());
412 return extent{floor(
static_cast<f32x4
>(rhs))};
415 [[nodiscard]]
constexpr friend extent min(
extent const &lhs,
extent const &rhs)
noexcept
417 return extent{min(
static_cast<f32x4
>(lhs),
static_cast<f32x4
>(rhs))};
420 [[nodiscard]]
constexpr friend extent max(
extent const &lhs,
extent const &rhs)
noexcept
422 return extent{max(
static_cast<f32x4
>(lhs),
static_cast<f32x4
>(rhs))};
427 return extent{clamp(
static_cast<f32x4
>(value),
static_cast<f32x4
>(min),
static_cast<f32x4
>(max))};
434 [[nodiscard]]
constexpr bool is_valid() const noexcept
436 return _v.x() >= 0.0f && _v.y() >= 0.0f && _v.z() >= 0.0f && _v.w() == 0.0f && (D == 3 || _v.z() == 0.0f);
441 if constexpr (D == 2) {
442 return std::format(
"[{}, {}]", rhs._v.x(), rhs._v.y());
443 }
else if constexpr (D == 3) {
444 return std::format(
"[{}, {}, {}]", rhs._v.x(), rhs._v.y(), rhs._v.z());
446 tt_static_no_default();
452 return lhs << to_string(rhs);
458 static constexpr size_t element_mask = (1_uz << D) - 1;
463using extent2 = geo::extent<2>;
464using extent3 = geo::extent<3>;
470template<
typename CharT>
471struct formatter<tt::geo::extent<2>, CharT> {
479 return std::vformat_to(fc.out(),
"[{}, {}]", std::make_format_args(t.
width(), t.
height()));
483template<
typename CharT>
484struct formatter<tt::geo::extent<3>, CharT> : formatter<float, CharT> {
492 return std::vformat_to(fc.out(),
"[{}, {}, {}]", std::make_format_args(t.
width(), t.
height(), t.
depth()));
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:186
constexpr float const & width() const noexcept
Access the x-as-width element from the extent.
Definition extent.hpp:175
constexpr friend bool operator>(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:337
constexpr friend bool operator<(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:309
constexpr float & width() noexcept
Access the x-as-width element from the extent.
Definition extent.hpp:142
constexpr friend bool operator<(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:316
constexpr friend extent operator*(float const &lhs, extent const &rhs) noexcept
Scale the extent by a scaler.
Definition extent.hpp:290
constexpr bool is_valid() const noexcept
Check if the extent is valid.
Definition extent.hpp:434
constexpr friend float squared_hypot(extent const &rhs) noexcept
Get the squared length of the extent.
Definition extent.hpp:367
constexpr friend extent operator-(extent const &lhs, extent const &rhs) noexcept
Subtract two extents from each other.
Definition extent.hpp:233
constexpr friend extent operator*(extent const &lhs, float const &rhs) noexcept
Scale the extent by a scaler.
Definition extent.hpp:244
constexpr friend bool operator<=(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:323
constexpr friend float rcp_hypot(extent const &rhs) noexcept
Get the length of the extent.
Definition extent.hpp:387
constexpr friend bool operator<=(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:330
constexpr friend extent normalize(extent const &rhs) noexcept
Normalize a extent to a unit extent.
Definition extent.hpp:397
constexpr extent(float width, float height, float depth=0.0f) noexcept
Construct a 3D extent from x, y and z elements.
Definition extent.hpp:90
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:80
constexpr float & depth() noexcept
Access the z-as-depth element from the extent.
Definition extent.hpp:164
constexpr friend float hypot(extent const &rhs) noexcept
Get the length of the extent.
Definition extent.hpp:377
constexpr friend extent operator+(extent const &lhs, float const &rhs) noexcept
Add a scaler to the extent.
Definition extent.hpp:273
constexpr float const & depth() const noexcept
Access the z-as-depth element from the extent.
Definition extent.hpp:197
constexpr friend bool operator>(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:344
constexpr float & height() noexcept
Access the y-as-height element from the extent.
Definition extent.hpp:153
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:301
constexpr extent() noexcept
Construct a empty extent / zero length.
Definition extent.hpp:71
constexpr friend bool operator>=(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:351
constexpr friend extent operator+(extent const &lhs, extent const &rhs) noexcept
Add two extents from each other.
Definition extent.hpp:222
constexpr friend bool operator>=(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:358
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector.hpp:20
T signaling_NaN(T... args)