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)
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)
91 [[nodiscard]]
constexpr float &
width() noexcept
102 [[nodiscard]]
constexpr float &
height() noexcept
113 [[nodiscard]]
constexpr float &
depth() noexcept requires(D == 3)
124 [[nodiscard]]
constexpr float const &
width() const noexcept
135 [[nodiscard]]
constexpr float const &
height() const noexcept
146 [[nodiscard]]
constexpr float const &
depth() const noexcept requires(D == 3)
151 [[nodiscard]]
constexpr vector<D> right() const noexcept
156 [[nodiscard]]
constexpr vector<D> up() const noexcept
158 return vector<D>{_v._0y00()};
168 tt_axiom(lhs.is_valid() && rhs.is_valid());
169 return extent{lhs._v + rhs._v};
179 tt_axiom(lhs.is_valid() && rhs.is_valid());
180 return extent{lhs._v - rhs._v};
190 tt_axiom(lhs.is_valid());
191 return extent{lhs._v * rhs};
197 tt_axiom(lhs.is_valid());
198 tt_axiom(rhs.is_valid());
204 [[nodiscard]]
constexpr friend auto operator+(vector<E>
const &lhs,
extent const &rhs)
noexcept
206 tt_axiom(lhs.is_valid());
207 tt_axiom(rhs.is_valid());
209 return vector<
std::max(D, E)>{
static_cast<f32x4
>(lhs) +
static_cast<f32x4
>(rhs)};
219 tt_axiom(lhs.is_valid());
222 for (
size_t i = 0; i != D; ++i) {
223 r._v[i] = lhs._v[i] + rhs;
236 tt_axiom(rhs.is_valid());
237 return extent{lhs * rhs._v};
247 tt_axiom(lhs.is_valid() && rhs.is_valid());
248 return lhs._v == rhs._v;
255 return lhs.width() < rhs.width() && lhs.height() < rhs.height();
262 return lhs.width() < rhs.width() && lhs.height() < rhs.height() && lhs.depth() < rhs.depth();
269 return lhs.width() <= rhs.width() && lhs.height() <= rhs.height();
276 return lhs.width() <= rhs.width() && lhs.height() <= rhs.height() && lhs.depth() <= rhs.depth();
283 return lhs.width() > rhs.width() && lhs.height() > rhs.height();
290 return lhs.width() > rhs.width() && lhs.height() > rhs.height() && lhs.depth() > rhs.depth();
297 return lhs.width() >= rhs.width() && lhs.height() >= rhs.height();
304 return lhs.width() >= rhs.width() && lhs.height() >= rhs.height() && lhs.depth() >= rhs.depth();
313 tt_axiom(rhs.is_valid());
314 return squared_hypot<element_mask>(rhs._v);
321 [[nodiscard]]
constexpr friend float hypot(
extent const &rhs)
noexcept
323 tt_axiom(rhs.is_valid());
324 return hypot<element_mask>(rhs._v);
333 tt_axiom(rhs.is_valid());
334 return rcp_hypot<element_mask>(rhs._v);
343 tt_axiom(rhs.is_valid());
344 return extent{normalize<element_mask>(rhs._v)};
347 [[nodiscard]]
constexpr friend extent ceil(
extent const &rhs)
noexcept
349 tt_axiom(rhs.is_valid());
353 [[nodiscard]]
constexpr friend extent floor(
extent const &rhs)
noexcept
355 tt_axiom(rhs.is_valid());
356 return extent{floor(
static_cast<f32x4
>(rhs))};
363 [[nodiscard]]
constexpr bool is_valid() const noexcept
365 return _v.x() >= 0.0f && _v.y() >= 0.0f && _v.z() >= 0.0f && _v.w() == 0.0f && (D == 3 || _v.z() == 0.0f);
370 if constexpr (D == 2) {
371 return fmt::format(
"[{}, {}]", rhs._v.x(), rhs._v.y());
372 }
else if constexpr (D == 3) {
373 return fmt::format(
"[{}, {}, {}]", rhs._v.x(), rhs._v.y(), rhs._v.z());
375 tt_static_no_default();
381 return lhs << to_string(rhs);
387 static constexpr size_t element_mask = (1_uz << D) - 1;
392using extent2 = geo::extent<2>;
393using 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:135
constexpr float const & width() const noexcept
Access the x-as-width element from the extent.
Definition extent.hpp:124
constexpr friend bool operator>(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:281
constexpr friend bool operator<(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:253
constexpr float & width() noexcept
Access the x-as-width element from the extent.
Definition extent.hpp:91
constexpr friend bool operator<(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:260
constexpr friend extent operator*(float const &lhs, extent const &rhs) noexcept
Scale the extent by a scaler.
Definition extent.hpp:234
constexpr bool is_valid() const noexcept
Check if the extent is valid.
Definition extent.hpp:363
constexpr friend float squared_hypot(extent const &rhs) noexcept
Get the squared length of the extent.
Definition extent.hpp:311
constexpr friend extent operator-(extent const &lhs, extent const &rhs) noexcept
Subtract two extents from each other.
Definition extent.hpp:177
constexpr friend extent operator*(extent const &lhs, float const &rhs) noexcept
Scale the extent by a scaler.
Definition extent.hpp:188
constexpr friend bool operator<=(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:267
constexpr friend float rcp_hypot(extent const &rhs) noexcept
Get the length of the extent.
Definition extent.hpp:331
constexpr friend bool operator<=(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:274
constexpr friend extent normalize(extent const &rhs) noexcept
Normalize a extent to a unit extent.
Definition extent.hpp:341
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:113
constexpr friend float hypot(extent const &rhs) noexcept
Get the length of the extent.
Definition extent.hpp:321
constexpr friend extent operator+(extent const &lhs, float const &rhs) noexcept
Add a scaler to the extent.
Definition extent.hpp:217
constexpr float const & depth() const noexcept
Access the z-as-depth element from the extent.
Definition extent.hpp:146
constexpr friend bool operator>(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:288
constexpr float & height() noexcept
Access the y-as-height element from the extent.
Definition extent.hpp:102
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:245
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:295
constexpr friend extent operator+(extent const &lhs, extent const &rhs) noexcept
Add two extents from each other.
Definition extent.hpp:166
constexpr friend bool operator>=(extent const &lhs, extent const &rhs) noexcept
Compare the size of the extents.
Definition extent.hpp:302
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector.hpp:20