15#include "../SIMD/module.hpp"
16#include "../utility/module.hpp"
17#include "../concurrency/module.hpp"
21namespace hi {
inline namespace v1 {
28 using array_type = simd<float, 4>;
29 using value_type = array_type::value_type;
41 return {point2{-large_number_v<float>, -large_number_v<float>}, point2{large_number_v<float>, large_number_v<float>}};
56 constexpr aarectangle(
float x,
float y,
float width,
float height) noexcept :
57 v{x, y, x + width, y + height}
66 constexpr explicit aarectangle(
extent2 const& extent) noexcept : v(
static_cast<array_type
>(extent)._00xy())
75 constexpr aarectangle(point2
const& p0, point2
const& p3) noexcept :
76 v(
static_cast<array_type
>(p0).xy00() +
static_cast<array_type
>(p3)._00xy())
91 v(
static_cast<array_type
>(p0).xyxy() +
static_cast<array_type
>(extent)._00xy())
96 constexpr explicit operator array_type() const noexcept
106 return (v <= v.zwzw()).mask() == 0b1111;
111 [[nodiscard]]
constexpr bool empty() const noexcept
113 return (v == v.zwxy()).mask() == 0b1111;
118 [[nodiscard]]
constexpr explicit operator bool() const noexcept
130 return *
this = *
this | rhs;
140 return *
this = *
this | rhs;
143 [[nodiscard]]
constexpr point2 operator[](
std::size_t i)
const noexcept
147 return point2{v.xy01()};
149 return point2{v.zy01()};
151 return point2{v.xw01()};
153 return point2{v.zw01()};
160 [[nodiscard]]
constexpr friend point2 get(aarectangle
const& rhs)
noexcept
162 if constexpr (I == 0) {
163 return point2{rhs.v.xy01()};
164 }
else if constexpr (I == 1) {
165 return point2{rhs.v.zy01()};
166 }
else if constexpr (I == 2) {
167 return point2{rhs.v.xw01()};
168 }
else if constexpr (I == 3) {
169 return point2{rhs.v.zw01()};
184 [[nodiscard]]
constexpr value_type x() const noexcept
189 [[nodiscard]]
constexpr value_type y() const noexcept
194 [[nodiscard]]
constexpr value_type width() const noexcept
196 return (v.zwzw() - v).x();
199 [[nodiscard]]
constexpr value_type height() const noexcept
201 return (v.zwzw() - v).y();
204 [[nodiscard]]
constexpr value_type bottom() const noexcept
209 [[nodiscard]]
constexpr value_type top() const noexcept
214 [[nodiscard]]
constexpr value_type left() const noexcept
219 [[nodiscard]]
constexpr value_type right() const noexcept
226 [[nodiscard]]
constexpr value_type
middle() const noexcept
228 return (bottom() + top()) / value_type{2};
233 [[nodiscard]]
constexpr value_type
center() const noexcept
235 return (left() + right()) / value_type{2};
242 return midpoint(get<0>(rhs), get<3>(rhs));
245 constexpr aarectangle& set_width(value_type newWidth)
noexcept
247 v = v.xyxw() + array_type{value_type{0}, value_type{0}, newWidth, value_type{0}};
251 constexpr aarectangle& set_height(value_type newHeight)
noexcept
253 v = v.xyzy() + array_type{value_type{0}, value_type{0}, value_type{0}, newHeight};
261 [[nodiscard]]
constexpr bool contains(point2
const& rhs)
const noexcept
264 return (
static_cast<array_type
>(rhs).xyxy() >= v).mask() == 0b0011;
272 [[nodiscard]]
constexpr bool contains(point3
const& rhs)
const noexcept
286 auto x = value_type{0};
291 x = haystack.right() - needle.width();
294 x = haystack.center() - needle.width() / value_type{2};
300 auto y = value_type{0};
302 y = haystack.bottom();
305 y = haystack.top() - needle.height();
308 y = haystack.middle() - needle.height() / value_type{2};
314 return {point2{x, y}, needle};
337 return equal(lhs.v, rhs.v);
342 if (lhs.empty() or rhs.
empty()) {
346 hilet rhs_swap = rhs.v.zwxy();
349 if (((lhs.v > rhs_swap).mask() & 0b0011) != 0) {
354 if (((lhs.v < rhs_swap).mask() & 0b1100) != 0) {
361 [[nodiscard]]
friend constexpr aarectangle operator|(aarectangle
const& lhs, aarectangle
const& rhs)
noexcept
368 return aarectangle{
min(get<0>(lhs), get<0>(rhs)),
max(get<3>(lhs), get<3>(rhs))};
372 [[nodiscard]]
friend constexpr aarectangle operator|(aarectangle
const& lhs, point2
const& rhs)
noexcept
375 return aarectangle{rhs, rhs};
377 return aarectangle{
min(get<0>(lhs), rhs),
max(get<3>(lhs), rhs)};
390 hilet offset = diff * 0.5f;
392 hilet p0 = get<0>(lhs) - offset;
393 hilet p3 = max(get<3>(lhs) + offset, p0);
405 return aarectangle{lhs.v + neg<0b0011>(array_type::broadcast(rhs))};
421 hilet p0 = round(get<0>(rhs));
463 hilet p0 = max(get<0>(lhs), get<0>(rhs));
464 hilet p3 = min(get<3>(lhs), get<3>(rhs));
465 if (p0.x() < p3.x() && p0.y() < p3.y()) {
472 [[nodiscard]]
friend value_type distance(
aarectangle const& lhs, point2
const& rhs)
noexcept
474 hilet lhs_ =
static_cast<array_type
>(lhs);
475 hilet rhs_ =
static_cast<array_type
>(rhs);
477 hilet closest_point = max(min(rhs_, lhs_.zwzw()), lhs_);
478 hilet v_closest_point = closest_point - rhs_;
479 return hypot<0b0011>(v_closest_point);
497 static constexpr bool is_always_lock_free =
false;
499 constexpr atomic()
noexcept =
default;
519 return is_always_lock_free;
522 void store(
value_type desired, std::memory_order = std::memory_order_seq_cst)
noexcept
528 value_type load(std::memory_order = std::memory_order_seq_cst)
const noexcept
537 return std::exchange(_value, desired);
543 if (_value == expected) {
555 std::memory_order success,
556 std::memory_order failure)
noexcept
570 std::memory_order order = std::memory_order_seq_cst)
noexcept
586 return _value |= arg;
594template<
typename CharT>
595struct std::formatter<
hi::aarectangle, CharT> {
603 return std::vformat_to(fc.out(),
"{}:{}", std::make_format_args(get<0>(t), t.
size()));
types and utilities for alignment.
Defined the geo::extent, extent2 and extent3 types.
#define hi_static_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:323
#define hi_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:279
#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
@ middle
Align to the vertical-middle.
@ bottom
Align to the bottom.
@ right
Align the text to the right side.
@ left
Align the text to the left side.
@ center
Align the text in the center.
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
@ inside
The border is drawn inside the edge of a quad.
@ outside
The border is drawn outside the edge of a quad.
An unfair mutex This is a fast implementation of a mutex which does not fairly arbitrate between mult...
Definition unfair_mutex.hpp:36
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:26
friend constexpr aarectangle ceil(aarectangle const &lhs, extent2 const &rhs) noexcept
Round rectangle by expanding to a certain granularity.
Definition aarectangle.hpp:437
constexpr extent2 size() const noexcept
Get size of the rectangle.
Definition aarectangle.hpp:179
friend constexpr aarectangle intersect(aarectangle const &lhs, aarectangle const &rhs) noexcept
Return the overlapping part of two rectangles.
Definition aarectangle.hpp:461
static constexpr aarectangle large() noexcept
Create a large axis aligned rectangle.
Definition aarectangle.hpp:39
friend constexpr aarectangle operator*(aarectangle const &lhs, value_type rhs) noexcept
Expand the rectangle for the same amount in all directions.
Definition aarectangle.hpp:386
constexpr friend point2 midpoint(aarectangle const &rhs) noexcept
Get the center of the rectangle.
Definition aarectangle.hpp:240
constexpr aarectangle(extent2 const &extent) noexcept
Create a rectangle from the size.
Definition aarectangle.hpp:66
friend constexpr aarectangle operator-(aarectangle const &lhs, value_type rhs) noexcept
Shrink the rectangle for the same amount in all directions.
Definition aarectangle.hpp:414
constexpr bool empty() const noexcept
Check if the rectangle has no area.
Definition aarectangle.hpp:111
constexpr bool contains(point3 const &rhs) const noexcept
Check if a 3D coordinate is inside the rectangle.
Definition aarectangle.hpp:272
constexpr bool contains(point2 const &rhs) const noexcept
Check if a 2D coordinate is inside the rectangle.
Definition aarectangle.hpp:261
static constexpr aarectangle _align(aarectangle outside, aarectangle inside, alignment alignment) noexcept
Need to call the hidden friend function from within another class.
Definition aarectangle.hpp:330
friend constexpr aarectangle floor(aarectangle const &rhs) noexcept
Round rectangle by shrinking to pixel edge.
Definition aarectangle.hpp:446
constexpr bool holds_invariant() const noexcept
Make sure p0 is left/bottom from p3.
Definition aarectangle.hpp:104
friend constexpr aarectangle align(aarectangle haystack, extent2 needle, alignment alignment) noexcept
Align a rectangle within another rectangle.
Definition aarectangle.hpp:284
friend constexpr aarectangle align(aarectangle haystack, aarectangle needle, alignment alignment) noexcept
Align a rectangle within another rectangle.
Definition aarectangle.hpp:323
friend constexpr aarectangle operator+(aarectangle const &lhs, value_type rhs) noexcept
Expand the rectangle for the same amount in all directions.
Definition aarectangle.hpp:403
constexpr value_type center() const noexcept
The center on the x-axis between left and right.
Definition aarectangle.hpp:233
constexpr aarectangle & operator|=(point2 const &rhs) noexcept
Expand the current rectangle to include the new rectangle.
Definition aarectangle.hpp:138
constexpr aarectangle(float x, float y, float width, float height) noexcept
Create a box from the position and size.
Definition aarectangle.hpp:56
friend constexpr aarectangle ceil(aarectangle const &rhs) noexcept
Round rectangle by expanding to pixel edge.
Definition aarectangle.hpp:428
constexpr aarectangle(point2 const &p0, point2 const &p3) noexcept
Create a rectangle from the left-bottom and right-top points.
Definition aarectangle.hpp:75
constexpr aarectangle & operator|=(aarectangle const &rhs) noexcept
Expand the current rectangle to include the new rectangle.
Definition aarectangle.hpp:128
constexpr value_type middle() const noexcept
The middle on the y-axis between bottom and top.
Definition aarectangle.hpp:226
constexpr aarectangle(point2 const &p0, extent2 const &extent) noexcept
Create a rectangle from the size.
Definition aarectangle.hpp:90
Horizontal/Vertical alignment combination.
Definition alignment.hpp:239
A high-level geometric extent.
Definition extent2.hpp:26
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector2.hpp:18
T compare_exchange_weak(T... args)
T is_lock_free(T... args)