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)
52 [[nodiscard]]
constexpr explicit operator vector<E>() const noexcept requires(E >= D)
60 [[nodiscard]]
constexpr extent() noexcept : _v(0.0f, 0.0f, 0.0f, 0.0f)
85 [[nodiscard]]
static constexpr extent infinity() noexcept requires(D == 2)
90 [[nodiscard]]
static constexpr extent infinity() noexcept requires(D == 3)
98 [[nodiscard]]
static constexpr extent large() noexcept requires(D == 2)
100 return extent{32767.0f, 32767.0f};
103 [[nodiscard]]
static constexpr extent large() noexcept requires(D == 3)
105 return extent{32767.0f, 32767.0f, 32767.0f};
108 [[nodiscard]]
static constexpr extent nan() noexcept requires(D == 2)
116 [[nodiscard]]
static constexpr extent nan() noexcept requires(D == 3)
131 [[nodiscard]]
constexpr float &
width() noexcept
142 [[nodiscard]]
constexpr float &
height() noexcept
153 [[nodiscard]]
constexpr float &
depth() noexcept requires(D == 3)
164 [[nodiscard]]
constexpr float const &
width() const noexcept
175 [[nodiscard]]
constexpr float const &
height() const noexcept
186 [[nodiscard]]
constexpr float const &
depth() const noexcept requires(D == 3)
191 [[nodiscard]]
constexpr vector<D> right() const noexcept
196 [[nodiscard]]
constexpr vector<D> up() const noexcept
198 return vector<D>{_v._0y00()};
201 constexpr extent &operator+=(
extent const &rhs)
noexcept
203 return *
this = *
this + rhs;
213 tt_axiom(lhs.is_valid() && rhs.is_valid());
214 return extent{lhs._v + rhs._v};
224 tt_axiom(lhs.is_valid() && rhs.is_valid());
225 return extent{lhs._v - rhs._v};
235 tt_axiom(lhs.is_valid());
236 return extent{lhs._v * rhs};
242 tt_axiom(lhs.is_valid());
243 tt_axiom(rhs.is_valid());
249 [[nodiscard]]
constexpr friend auto operator+(vector<E>
const &lhs,
extent const &rhs)
noexcept
251 tt_axiom(lhs.is_valid());
252 tt_axiom(rhs.is_valid());
254 return vector<
std::max(D, E)>{
static_cast<f32x4
>(lhs) +
static_cast<f32x4
>(rhs)};
264 tt_axiom(lhs.is_valid());
267 for (
size_t i = 0; i != D; ++i) {
268 r._v[i] = lhs._v[i] + rhs;
281 tt_axiom(rhs.is_valid());
282 return extent{lhs * rhs._v};
292 tt_axiom(lhs.is_valid() && rhs.is_valid());
293 return lhs._v == rhs._v;
300 return lhs.width() < rhs.width() && lhs.height() < rhs.height();
307 return lhs.width() < rhs.width() && lhs.height() < rhs.height() && lhs.depth() < rhs.depth();
314 return lhs.width() <= rhs.width() && lhs.height() <= rhs.height();
321 return lhs.width() <= rhs.width() && lhs.height() <= rhs.height() && lhs.depth() <= rhs.depth();
328 return lhs.width() > rhs.width() && lhs.height() > rhs.height();
335 return lhs.width() > rhs.width() && lhs.height() > rhs.height() && lhs.depth() > rhs.depth();
342 return lhs.width() >= rhs.width() && lhs.height() >= rhs.height();
349 return lhs.width() >= rhs.width() && lhs.height() >= rhs.height() && lhs.depth() >= rhs.depth();
358 tt_axiom(rhs.is_valid());
359 return squared_hypot<element_mask>(rhs._v);
366 [[nodiscard]]
constexpr friend float hypot(
extent const &rhs)
noexcept
368 tt_axiom(rhs.is_valid());
369 return hypot<element_mask>(rhs._v);
378 tt_axiom(rhs.is_valid());
379 return rcp_hypot<element_mask>(rhs._v);
388 tt_axiom(rhs.is_valid());
389 return extent{normalize<element_mask>(rhs._v)};
392 [[nodiscard]]
constexpr friend extent ceil(
extent const &rhs)
noexcept
394 tt_axiom(rhs.is_valid());
398 [[nodiscard]]
constexpr friend extent floor(
extent const &rhs)
noexcept
400 tt_axiom(rhs.is_valid());
401 return extent{floor(
static_cast<f32x4
>(rhs))};
404 [[nodiscard]]
constexpr friend extent min(
extent const &lhs,
extent const &rhs)
noexcept
406 return extent{min(
static_cast<f32x4
>(lhs),
static_cast<f32x4
>(rhs))};
409 [[nodiscard]]
constexpr friend extent max(
extent const &lhs,
extent const &rhs)
noexcept
411 return extent{max(
static_cast<f32x4
>(lhs),
static_cast<f32x4
>(rhs))};
416 return extent{clamp(
static_cast<f32x4
>(value),
static_cast<f32x4
>(min),
static_cast<f32x4
>(max))};
423 [[nodiscard]]
constexpr bool is_valid() const noexcept
425 return _v.x() >= 0.0f && _v.y() >= 0.0f && _v.z() >= 0.0f && _v.w() == 0.0f && (D == 3 || _v.z() == 0.0f);
430 if constexpr (D == 2) {
431 return std::format(
"[{}, {}]", rhs._v.x(), rhs._v.y());
432 }
else if constexpr (D == 3) {
433 return std::format(
"[{}, {}, {}]", rhs._v.x(), rhs._v.y(), rhs._v.z());
435 tt_static_no_default();
441 return lhs << to_string(rhs);
447 static constexpr size_t element_mask = (1_uz << D) - 1;
452using extent2 = geo::extent<2>;
453using extent3 = geo::extent<3>;
459template<
typename CharT>
460struct formatter<tt::geo::extent<2>, CharT> {
468 return std::vformat_to(fc.out(),
"[{}, {}]", std::make_format_args(t.
width(), t.
height()));
472template<
typename CharT>
473struct formatter<tt::geo::extent<3>, CharT> : formatter<float, CharT> {
481 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:175
constexpr float const & width() const noexcept
Access the x-as-width element from the extent.
Definition extent.hpp:164
constexpr friend bool operator>(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:326
constexpr friend bool operator<(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:298
constexpr float & width() noexcept
Access the x-as-width element from the extent.
Definition extent.hpp:131
constexpr friend bool operator<(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:305
constexpr friend extent operator*(float const &lhs, extent const &rhs) noexcept
Scale the extent by a scaler.
Definition extent.hpp:279
constexpr bool is_valid() const noexcept
Check if the extent is valid.
Definition extent.hpp:423
constexpr friend float squared_hypot(extent const &rhs) noexcept
Get the squared length of the extent.
Definition extent.hpp:356
constexpr friend extent operator-(extent const &lhs, extent const &rhs) noexcept
Subtract two extents from each other.
Definition extent.hpp:222
constexpr friend extent operator*(extent const &lhs, float const &rhs) noexcept
Scale the extent by a scaler.
Definition extent.hpp:233
constexpr friend bool operator<=(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:312
constexpr friend float rcp_hypot(extent const &rhs) noexcept
Get the length of the extent.
Definition extent.hpp:376
constexpr friend bool operator<=(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:319
constexpr friend extent normalize(extent const &rhs) noexcept
Normalize a extent to a unit extent.
Definition extent.hpp:386
constexpr extent(float width, float height, float depth=0.0f) noexcept
Construct a 3D extent from x, y and z elements.
Definition extent.hpp:79
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:69
constexpr float & depth() noexcept
Access the z-as-depth element from the extent.
Definition extent.hpp:153
constexpr friend float hypot(extent const &rhs) noexcept
Get the length of the extent.
Definition extent.hpp:366
constexpr friend extent operator+(extent const &lhs, float const &rhs) noexcept
Add a scaler to the extent.
Definition extent.hpp:262
constexpr float const & depth() const noexcept
Access the z-as-depth element from the extent.
Definition extent.hpp:186
constexpr friend bool operator>(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:333
constexpr float & height() noexcept
Access the y-as-height element from the extent.
Definition extent.hpp:142
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:290
constexpr extent() noexcept
Construct a empty extent / zero length.
Definition extent.hpp:60
constexpr friend bool operator>=(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:340
constexpr friend extent operator+(extent const &lhs, extent const &rhs) noexcept
Add two extents from each other.
Definition extent.hpp:211
constexpr friend bool operator>=(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:347
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)