12#include "../SIMD/module.hpp"
13#include "../utility/module.hpp"
17namespace hi {
inline namespace v1 {
28 using array_type = simd<float, 4>;
29 using value_type = array_type::value_type;
36 [[nodiscard]]
constexpr explicit extent2(array_type
const&
other) noexcept : _v(
other)
43 [[nodiscard]]
constexpr explicit operator array_type() const noexcept
53 [[nodiscard]]
constexpr explicit operator vector2() const noexcept
55 return vector2{
static_cast<array_type
>(*this)};
60 [[nodiscard]]
constexpr extent2() noexcept : _v(0.0f, 0.0f, 0.0f, 0.0f) {}
72 [[nodiscard]]
static constexpr extent2 infinity() noexcept
77 [[nodiscard]]
static constexpr extent2 large() noexcept
79 return extent2{large_number_v<float>, large_number_v<float>};
82 [[nodiscard]]
static constexpr extent2 nan() noexcept
90 [[nodiscard]]
constexpr explicit operator bool() const noexcept
92 return _v.x() != 0.0f or _v.y() != 0.0f or _v.z() != 0.0f;
101 [[nodiscard]]
constexpr float&
width() noexcept
112 [[nodiscard]]
constexpr float&
height() noexcept
123 [[nodiscard]]
constexpr float width() const noexcept
134 [[nodiscard]]
constexpr float height() const noexcept
139 [[nodiscard]]
constexpr vector2 right() const noexcept
144 [[nodiscard]]
constexpr vector2 up() const noexcept
146 return vector2{_v._0y00()};
151 return *
this = *
this + rhs;
161 return extent2{lhs._v + rhs._v};
171 return extent2{lhs._v - rhs._v};
186 return extent2{
static_cast<array_type
>(lhs) +
static_cast<array_type
>(rhs)};
189 [[nodiscard]]
constexpr friend vector2
operator+(vector2
const& lhs,
extent2 const& rhs)
noexcept
191 return vector2{
static_cast<array_type
>(lhs) +
static_cast<array_type
>(rhs)};
203 r._v[i] = lhs._v[i] + rhs;
226 return equal(lhs._v, rhs._v);
229 [[nodiscard]]
constexpr friend std::partial_ordering operator<=>(
extent2 const& lhs,
extent2 const& rhs)
noexcept
233 hilet equal = (lhs._v == rhs._v).mask() & mask;
236 return std::partial_ordering::equivalent;
239 hilet less = (lhs._v < rhs._v).mask() & mask;
240 if ((less | equal) == mask) {
242 return std::partial_ordering::less;
245 hilet greater = (lhs._v > rhs._v).mask() & mask;
246 if ((greater | equal) == mask) {
248 return std::partial_ordering::greater;
252 return std::partial_ordering::unordered;
261 return squared_hypot<0b0011>(rhs._v);
270 return hypot<0b0011>(rhs._v);
279 return rcp_hypot<0b0011>(rhs._v);
288 return extent2{normalize<0b0011>(rhs._v)};
291 [[nodiscard]]
constexpr friend extent2 ceil(
extent2 const& rhs)
noexcept
293 return extent2{ceil(array_type{rhs})};
296 [[nodiscard]]
constexpr friend extent2 floor(
extent2 const& rhs)
noexcept
298 return extent2{floor(
static_cast<array_type
>(rhs))};
301 [[nodiscard]]
constexpr friend extent2 round(
extent2 const& rhs)
noexcept
303 return extent2{round(
static_cast<array_type
>(rhs))};
308 return extent2{min(
static_cast<array_type
>(lhs),
static_cast<array_type
>(rhs))};
313 return extent2{max(
static_cast<array_type
>(lhs),
static_cast<array_type
>(rhs))};
318 return extent2{clamp(
static_cast<array_type
>(value),
static_cast<array_type
>(min),
static_cast<array_type
>(max))};
327 return _v.x() >= 0.0f and _v.y() >= 0.0f and _v.z() == 0.0f and _v.w() == 0.0f;
332 return std::format(
"[{}, {}]", rhs._v.x(), rhs._v.y());
337 return lhs << to_string(rhs);
346template<
typename CharT>
347struct std::formatter<
hi::extent2, CharT> {
355 return std::vformat_to(fc.out(),
"[{}, {}]", std::make_format_args(t.
width(), t.
height()));
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
A high-level geometric extent.
Definition extent2.hpp:26
constexpr float width() const noexcept
Access the x-as-width element from the extent.
Definition extent2.hpp:123
friend float hypot(extent2 const &rhs) noexcept
Get the length of the extent.
Definition extent2.hpp:268
constexpr friend extent2 operator*(float const &lhs, extent2 const &rhs) noexcept
Scale the extent by a scaler.
Definition extent2.hpp:214
constexpr float height() const noexcept
Access the y-as-height element from the extent.
Definition extent2.hpp:134
hi_force_inline constexpr friend float squared_hypot(extent2 const &rhs) noexcept
Get the squared length of the extent.
Definition extent2.hpp:259
constexpr friend extent2 operator+(extent2 const &lhs, float const &rhs) noexcept
Add a scaler to the extent.
Definition extent2.hpp:199
constexpr friend extent2 operator*(extent2 const &lhs, float const &rhs) noexcept
Scale the extent by a scaler.
Definition extent2.hpp:179
constexpr friend bool operator==(extent2 const &lhs, extent2 const &rhs) noexcept
Compare if two extents are equal.
Definition extent2.hpp:224
constexpr friend extent2 operator-(extent2 const &lhs, extent2 const &rhs) noexcept
Subtract two extents from each other.
Definition extent2.hpp:169
constexpr friend float rcp_hypot(extent2 const &rhs) noexcept
Get the length of the extent.
Definition extent2.hpp:277
constexpr float & width() noexcept
Access the x-as-width element from the extent.
Definition extent2.hpp:101
constexpr extent2() noexcept
Construct a empty extent / zero length.
Definition extent2.hpp:60
constexpr float & height() noexcept
Access the y-as-height element from the extent.
Definition extent2.hpp:112
constexpr friend extent2 operator+(extent2 const &lhs, extent2 const &rhs) noexcept
Add two extents from each other.
Definition extent2.hpp:159
constexpr bool holds_invariant() const noexcept
Check if the extent is valid.
Definition extent2.hpp:325
constexpr friend extent2 normalize(extent2 const &rhs) noexcept
Normalize a extent to a unit extent.
Definition extent2.hpp:286
constexpr extent2(float width, float height) noexcept
Construct a 3D extent from width, height and depth.
Definition extent2.hpp:67
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector2.hpp:18
T signaling_NaN(T... args)