12#include "../SIMD/module.hpp"
13#include "../utility/utility.hpp"
14#include "../macros.hpp"
20namespace hi {
inline namespace v1 {
31 using array_type = simd<float, 4>;
32 using value_type = array_type::value_type;
39 [[nodiscard]]
constexpr explicit extent2(array_type
const&
other) noexcept : _v(
other)
46 [[nodiscard]]
constexpr explicit operator array_type() const noexcept
56 [[nodiscard]]
constexpr explicit operator vector2() const noexcept
58 return vector2{
static_cast<array_type
>(*this)};
63 [[nodiscard]]
constexpr extent2() noexcept : _v(0.0f, 0.0f, 0.0f, 0.0f) {}
75 [[nodiscard]]
constexpr static extent2 infinity() noexcept
80 [[nodiscard]]
constexpr static extent2 large() noexcept
82 return extent2{large_number_v<float>, large_number_v<float>};
85 [[nodiscard]]
constexpr static extent2 nan() noexcept
93 [[nodiscard]]
constexpr explicit operator bool() const noexcept
95 return _v.x() != 0.0f or _v.y() != 0.0f or _v.z() != 0.0f;
104 [[nodiscard]]
constexpr float&
width() noexcept
115 [[nodiscard]]
constexpr float&
height() noexcept
126 [[nodiscard]]
constexpr float width() const noexcept
137 [[nodiscard]]
constexpr float height() const noexcept
142 [[nodiscard]]
constexpr vector2 right() const noexcept
147 [[nodiscard]]
constexpr vector2 up() const noexcept
149 return vector2{_v._0y00()};
152 constexpr extent2& operator+=(extent2
const& rhs)
noexcept
154 return *
this = *
this + rhs;
162 [[nodiscard]]
constexpr friend extent2
operator+(extent2
const& lhs, extent2
const& rhs)
noexcept
164 return extent2{lhs._v + rhs._v};
172 [[nodiscard]]
constexpr friend extent2
operator-(extent2
const& lhs, extent2
const& rhs)
noexcept
174 return extent2{lhs._v - rhs._v};
182 [[nodiscard]]
constexpr friend extent2
operator*(extent2
const& lhs,
float const& rhs)
noexcept
184 return extent2{lhs._v * rhs};
189 return extent2{
static_cast<array_type
>(lhs) +
static_cast<array_type
>(rhs)};
192 [[nodiscard]]
constexpr friend vector2
operator+(vector2
const& lhs,
extent2 const& rhs)
noexcept
194 return vector2{
static_cast<array_type
>(lhs) +
static_cast<array_type
>(rhs)};
202 [[nodiscard]]
constexpr friend extent2
operator+(extent2
const& lhs,
float const& rhs)
noexcept
206 r._v[i] = lhs._v[i] + rhs;
217 [[nodiscard]]
constexpr friend extent2
operator*(
float const& lhs, extent2
const& rhs)
noexcept
219 return extent2{lhs * rhs._v};
227 [[nodiscard]]
constexpr friend bool operator==(extent2
const& lhs, extent2
const& rhs)
noexcept
229 return equal(lhs._v, rhs._v);
232 [[nodiscard]]
constexpr friend std::partial_ordering operator<=>(
extent2 const& lhs,
extent2 const& rhs)
noexcept
236 hilet equal = (lhs._v == rhs._v).mask() & mask;
239 return std::partial_ordering::equivalent;
242 hilet less = (lhs._v < rhs._v).mask() & mask;
243 if ((less | equal) == mask) {
245 return std::partial_ordering::less;
248 hilet greater = (lhs._v > rhs._v).mask() & mask;
249 if ((greater | equal) == mask) {
251 return std::partial_ordering::greater;
255 return std::partial_ordering::unordered;
262 [[nodiscard]] hi_force_inline
constexpr friend float squared_hypot(extent2
const& rhs)
noexcept
271 [[nodiscard]]
friend float hypot(extent2
const& rhs)
noexcept
280 [[nodiscard]]
constexpr friend float rcp_hypot(extent2
const& rhs)
noexcept
289 [[nodiscard]]
constexpr friend extent2
normalize(extent2
const& rhs)
noexcept
294 [[nodiscard]]
constexpr friend extent2 ceil(
extent2 const& rhs)
noexcept
296 return extent2{ceil(array_type{rhs})};
299 [[nodiscard]]
constexpr friend extent2 floor(extent2
const& rhs)
noexcept
301 return extent2{floor(
static_cast<array_type
>(rhs))};
304 [[nodiscard]]
constexpr friend extent2 round(extent2
const& rhs)
noexcept
306 return extent2{round(
static_cast<array_type
>(rhs))};
309 [[nodiscard]]
constexpr friend extent2 min(extent2
const& lhs, extent2
const& rhs)
noexcept
311 return extent2{min(
static_cast<array_type
>(lhs),
static_cast<array_type
>(rhs))};
314 [[nodiscard]]
constexpr friend extent2 max(extent2
const& lhs, extent2
const& rhs)
noexcept
316 return extent2{max(
static_cast<array_type
>(lhs),
static_cast<array_type
>(rhs))};
319 [[nodiscard]]
constexpr friend extent2 clamp(extent2
const& value, extent2
const& min, extent2
const& max)
noexcept
321 return extent2{clamp(
static_cast<array_type
>(value),
static_cast<array_type
>(min),
static_cast<array_type
>(max))};
330 return _v.x() >= 0.0f and _v.y() >= 0.0f and _v.z() == 0.0f and _v.w() == 0.0f;
335 return std::format(
"[{}, {}]", rhs._v.x(), rhs._v.y());
340 return lhs << to_string(rhs);
349template<
typename CharT>
350struct std::formatter<
hi::extent2, CharT> {
358 return std::vformat_to(fc.out(),
"[{}, {}]", std::make_format_args(t.
width(), t.
height()));
@ other
The gui_event does not have associated data.
Definition gui_event_variant.hpp:22
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
The HikoGUI API version 1.
Definition lookahead_iterator.hpp:6
A high-level geometric extent.
Definition extent2.hpp:29
constexpr float width() const noexcept
Access the x-as-width element from the extent.
Definition extent2.hpp:126
friend float hypot(extent2 const &rhs) noexcept
Get the length of the extent.
Definition extent2.hpp:271
constexpr friend extent2 operator*(float const &lhs, extent2 const &rhs) noexcept
Scale the extent by a scaler.
Definition extent2.hpp:217
constexpr float height() const noexcept
Access the y-as-height element from the extent.
Definition extent2.hpp:137
hi_force_inline constexpr friend float squared_hypot(extent2 const &rhs) noexcept
Get the squared length of the extent.
Definition extent2.hpp:262
constexpr friend extent2 operator+(extent2 const &lhs, float const &rhs) noexcept
Add a scaler to the extent.
Definition extent2.hpp:202
constexpr friend extent2 operator*(extent2 const &lhs, float const &rhs) noexcept
Scale the extent by a scaler.
Definition extent2.hpp:182
constexpr friend bool operator==(extent2 const &lhs, extent2 const &rhs) noexcept
Compare if two extents are equal.
Definition extent2.hpp:227
constexpr friend extent2 operator-(extent2 const &lhs, extent2 const &rhs) noexcept
Subtract two extents from each other.
Definition extent2.hpp:172
constexpr friend float rcp_hypot(extent2 const &rhs) noexcept
Get the length of the extent.
Definition extent2.hpp:280
constexpr float & width() noexcept
Access the x-as-width element from the extent.
Definition extent2.hpp:104
constexpr extent2() noexcept
Construct a empty extent / zero length.
Definition extent2.hpp:63
constexpr float & height() noexcept
Access the y-as-height element from the extent.
Definition extent2.hpp:115
constexpr friend extent2 operator+(extent2 const &lhs, extent2 const &rhs) noexcept
Add two extents from each other.
Definition extent2.hpp:162
constexpr bool holds_invariant() const noexcept
Check if the extent is valid.
Definition extent2.hpp:328
constexpr friend extent2 normalize(extent2 const &rhs) noexcept
Normalize a extent to a unit extent.
Definition extent2.hpp:289
constexpr extent2(float width, float height) noexcept
Construct a 3D extent from width, height and depth.
Definition extent2.hpp:70
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector2.hpp:19
T signaling_NaN(T... args)