12#include "../utility/utility.hpp"
13#include "../macros.hpp"
14#include <hikocpu/hikocpu.hpp>
21hi_export_module(hikogui.geometry : extent2);
23hi_export
namespace hi {
inline namespace v1 {
35 using value_type = array_type::value_type;
42 [[nodiscard]]
constexpr explicit extent2(array_type
const&
other) noexcept : _v(
other)
49 [[nodiscard]]
constexpr explicit operator array_type() const noexcept
59 [[nodiscard]]
constexpr explicit operator vector2() const noexcept
61 return vector2{
static_cast<array_type
>(*this)};
66 [[nodiscard]]
constexpr extent2() noexcept : _v(0.0f, 0.0f, 0.0f, 0.0f) {}
78 [[nodiscard]]
constexpr static extent2 infinity() noexcept
83 [[nodiscard]]
constexpr static extent2 large() noexcept
85 return extent2{large_number_v<float>, large_number_v<float>};
88 [[nodiscard]]
constexpr static extent2 nan() noexcept
96 [[nodiscard]]
constexpr explicit operator bool() const noexcept
98 return _v.x() != 0.0f or _v.y() != 0.0f or _v.z() != 0.0f;
107 [[nodiscard]]
constexpr float&
width() noexcept
118 [[nodiscard]]
constexpr float&
height() noexcept
129 [[nodiscard]]
constexpr float width() const noexcept
140 [[nodiscard]]
constexpr float height() const noexcept
145 [[nodiscard]]
constexpr vector2 right() const noexcept
150 [[nodiscard]]
constexpr vector2 up() const noexcept
152 return vector2{_v._0y00()};
155 constexpr extent2& operator+=(extent2
const& rhs)
noexcept
157 return *
this = *
this + rhs;
165 [[nodiscard]]
constexpr friend extent2
operator+(extent2
const& lhs, extent2
const& rhs)
noexcept
167 return extent2{lhs._v + rhs._v};
175 [[nodiscard]]
constexpr friend extent2
operator-(extent2
const& lhs, extent2
const& rhs)
noexcept
177 return extent2{lhs._v - rhs._v};
185 [[nodiscard]]
constexpr friend extent2
operator*(extent2
const& lhs,
float const& rhs)
noexcept
187 return extent2{lhs._v * array_type::broadcast(rhs)};
192 return extent2{
static_cast<array_type
>(lhs) +
static_cast<array_type
>(rhs)};
195 [[nodiscard]]
constexpr friend vector2
operator+(vector2
const& lhs,
extent2 const& rhs)
noexcept
197 return vector2{
static_cast<array_type
>(lhs) +
static_cast<array_type
>(rhs)};
205 [[nodiscard]]
constexpr friend extent2
operator+(extent2
const& lhs,
float const& rhs)
noexcept
209 r._v[i] = lhs._v[i] + rhs;
220 [[nodiscard]]
constexpr friend extent2
operator*(
float const& lhs, extent2
const& rhs)
noexcept
222 return extent2{array_type::broadcast(lhs) * rhs._v};
230 [[nodiscard]]
constexpr friend bool operator==(extent2
const& lhs, extent2
const& rhs)
noexcept
232 return equal(lhs._v, rhs._v);
235 [[nodiscard]]
constexpr friend std::partial_ordering operator<=>(
extent2 const& lhs,
extent2 const& rhs)
noexcept
239 auto const equal = (lhs._v == rhs._v).mask() & mask;
242 return std::partial_ordering::equivalent;
245 auto const less = (lhs._v < rhs._v).mask() & mask;
246 if ((less | equal) == mask) {
248 return std::partial_ordering::less;
251 auto const greater = (lhs._v > rhs._v).mask() & mask;
252 if ((greater | equal) == mask) {
254 return std::partial_ordering::greater;
258 return std::partial_ordering::unordered;
265 [[nodiscard]] hi_force_inline
constexpr friend float squared_hypot(extent2
const& rhs)
noexcept
267 return dot<0b0011>(rhs._v, rhs._v).x();
274 [[nodiscard]]
friend float hypot(extent2
const& rhs)
noexcept
283 [[nodiscard]]
constexpr friend float rcp_hypot(extent2
const& rhs)
noexcept
285 return rhypot<0b0011>(rhs._v).x();
292 [[nodiscard]]
constexpr friend extent2
normalize(extent2
const& rhs)
noexcept
297 [[nodiscard]]
constexpr friend extent2 ceil(
extent2 const& rhs)
noexcept
299 return extent2{ceil(array_type{rhs})};
302 [[nodiscard]]
constexpr friend extent2 floor(extent2
const& rhs)
noexcept
304 return extent2{floor(
static_cast<array_type
>(rhs))};
307 [[nodiscard]]
constexpr friend extent2 round(extent2
const& rhs)
noexcept
309 return extent2{round(
static_cast<array_type
>(rhs))};
312 [[nodiscard]]
constexpr friend extent2 min(extent2
const& lhs, extent2
const& rhs)
noexcept
314 return extent2{min(
static_cast<array_type
>(lhs),
static_cast<array_type
>(rhs))};
317 [[nodiscard]]
constexpr friend extent2 max(extent2
const& lhs, extent2
const& rhs)
noexcept
319 return extent2{max(
static_cast<array_type
>(lhs),
static_cast<array_type
>(rhs))};
322 [[nodiscard]]
constexpr friend extent2 clamp(extent2
const& value, extent2
const& min, extent2
const& max)
noexcept
324 return extent2{clamp(
static_cast<array_type
>(value),
static_cast<array_type
>(min),
static_cast<array_type
>(max))};
333 return _v.x() >= 0.0f and _v.y() >= 0.0f and _v.z() == 0.0f and _v.w() == 0.0f;
338 return std::format(
"[{}, {}]", rhs._v.x(), rhs._v.y());
343 return lhs << to_string(rhs);
354struct std::formatter<
hi::extent2, char> : std::formatter<std::string, char> {
357 return std::formatter<std::string, char>::format(std::format(
"[{}, {}]", t.
width(), t.
height()), fc);
@ other
The gui_event does not have associated data.
Definition gui_event_variant.hpp:24
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
Definition simd_intf.hpp:18
A high-level geometric extent.
Definition extent2.hpp:32
constexpr float width() const noexcept
Access the x-as-width element from the extent.
Definition extent2.hpp:129
friend float hypot(extent2 const &rhs) noexcept
Get the length of the extent.
Definition extent2.hpp:274
constexpr friend extent2 operator*(float const &lhs, extent2 const &rhs) noexcept
Scale the extent by a scaler.
Definition extent2.hpp:220
constexpr float height() const noexcept
Access the y-as-height element from the extent.
Definition extent2.hpp:140
hi_force_inline constexpr friend float squared_hypot(extent2 const &rhs) noexcept
Get the squared length of the extent.
Definition extent2.hpp:265
constexpr friend extent2 operator+(extent2 const &lhs, float const &rhs) noexcept
Add a scaler to the extent.
Definition extent2.hpp:205
constexpr friend extent2 operator*(extent2 const &lhs, float const &rhs) noexcept
Scale the extent by a scaler.
Definition extent2.hpp:185
constexpr friend bool operator==(extent2 const &lhs, extent2 const &rhs) noexcept
Compare if two extents are equal.
Definition extent2.hpp:230
constexpr friend extent2 operator-(extent2 const &lhs, extent2 const &rhs) noexcept
Subtract two extents from each other.
Definition extent2.hpp:175
constexpr friend float rcp_hypot(extent2 const &rhs) noexcept
Get the length of the extent.
Definition extent2.hpp:283
constexpr float & width() noexcept
Access the x-as-width element from the extent.
Definition extent2.hpp:107
constexpr extent2() noexcept
Construct a empty extent / zero length.
Definition extent2.hpp:66
constexpr float & height() noexcept
Access the y-as-height element from the extent.
Definition extent2.hpp:118
constexpr friend extent2 operator+(extent2 const &lhs, extent2 const &rhs) noexcept
Add two extents from each other.
Definition extent2.hpp:165
constexpr bool holds_invariant() const noexcept
Check if the extent is valid.
Definition extent2.hpp:331
constexpr friend extent2 normalize(extent2 const &rhs) noexcept
Normalize a extent to a unit extent.
Definition extent2.hpp:292
constexpr extent2(float width, float height) noexcept
Construct a 3D extent from width, height and depth.
Definition extent2.hpp:73
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector2.hpp:27
T signaling_NaN(T... args)