15#include "../SIMD/SIMD.hpp"
16#include "../utility/utility.hpp"
17#include "../concurrency/concurrency.hpp"
20#include "../macros.hpp"
26hi_export_module(hikogui.geometry : aarectangle);
28hi_export
namespace hi {
inline namespace v1 {
36 using value_type = array_type::value_type;
64 v{x, y, x + width, y + height}
85 hi_axiom(p0.holds_invariant());
86 hi_axiom(p3.holds_invariant());
113 return (v <= v.zwzw()).mask() == 0b1111;
120 return (v == v.zwxy()).mask() == 0b1111;
137 return *
this = *
this | rhs;
147 return *
this = *
this | rhs;
154 return point2{v.xy01()};
156 return point2{v.zy01()};
158 return point2{v.xw01()};
160 return point2{v.zw01()};
167 [[
nodiscard]]
constexpr friend point2 get(aarectangle
const &rhs)
noexcept
169 if constexpr (I == 0) {
170 return point2{rhs.v.xy01()};
171 }
else if constexpr (I == 1) {
172 return point2{rhs.v.zy01()};
173 }
else if constexpr (I == 2) {
174 return point2{rhs.v.xw01()};
175 }
else if constexpr (I == 3) {
176 return point2{rhs.v.zw01()};
178 hi_static_no_default();
203 return (v.zwzw() - v).x();
208 return (v.zwzw() - v).y();
235 return (bottom() + top()) / value_type{2};
242 return (left() + right()) / value_type{2};
254 v = v.xyxw() + array_type{value_type{0}, value_type{0},
newWidth, value_type{0}};
258 constexpr aarectangle& set_height(value_type
newHeight)
noexcept
260 v = v.xyzy() + array_type{value_type{0}, value_type{0}, value_type{0},
newHeight};
271 return (
static_cast<array_type>(rhs).
xyxy() >= v).mask() == 0b0011;
293 auto x = value_type{0};
307 auto y = value_type{0};
321 return {point2{x, y},
needle};
344 return equal(lhs.v, rhs.v);
349 if (lhs.empty()
or rhs.
empty()) {
356 if (((lhs.v >
rhs_swap).mask() & 0b0011) != 0) {
361 if (((lhs.v <
rhs_swap).mask() & 0b1100) != 0) {
368 [[
nodiscard]]
friend constexpr aarectangle operator|(aarectangle
const& lhs, aarectangle
const& rhs)
noexcept
379 [[
nodiscard]]
friend constexpr aarectangle operator|(aarectangle
const& lhs, point2
const& rhs)
noexcept
382 return aarectangle{rhs, rhs};
397 auto const offset =
diff * 0.5f;
399 auto const p0 =
get<0>(lhs) - offset;
400 auto const p3 = max(
get<3>(lhs) + offset, p0);
417 return lhs = lhs + rhs;
433 return lhs = lhs - rhs;
438 auto const p0 = round(
get<0>(rhs));
439 auto const size = round(rhs.
size());
482 if (p0.x() < p3.x() && p0.y() < p3.y()) {
491 auto const lhs_ =
static_cast<array_type
>(lhs);
492 auto const rhs_ =
static_cast<array_type
>(rhs);
514 constexpr static bool is_always_lock_free =
false;
516 constexpr atomic()
noexcept =
default;
536 return is_always_lock_free;
539 void store(
value_type desired, std::memory_order = std::memory_order_seq_cst)
noexcept
541 auto const lock = std::scoped_lock(_mutex);
545 value_type load(std::memory_order = std::memory_order_seq_cst)
const noexcept
547 auto const lock = std::scoped_lock(_mutex);
553 auto const lock = std::scoped_lock(_mutex);
554 return std::exchange(_value, desired);
559 auto const lock = std::scoped_lock(_mutex);
560 if (_value == expected) {
572 std::memory_order success,
573 std::memory_order failure)
noexcept
587 std::memory_order order = std::memory_order_seq_cst)
noexcept
594 auto const lock = std::scoped_lock(_mutex);
602 auto const lock = std::scoped_lock(_mutex);
603 return _value |= arg;
613struct std::formatter<
hi::aarectangle, char> {
621 return std::vformat_to(fc.out(),
"{}:{}", std::make_format_args(get<0>(t), t.
size()));
Functions and types for accessing operating system threads.
Definition of the unfair_mutex.
types and utilities for alignment.
Defined the geo::extent, extent2 and extent3 types.
@ 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_misc.hpp:20
The HikoGUI namespace.
Definition recursive_iterator.hpp:15
@ inside
The border is drawn inside the edge of a quad.
@ outside
The border is drawn outside the edge of a quad.
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:378
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
friend constexpr aarectangle ceil(aarectangle const &lhs, extent2 const &rhs) noexcept
Round rectangle by expanding to a certain granularity.
Definition aarectangle.hpp:454
constexpr extent2 size() const noexcept
Get size of the rectangle.
Definition aarectangle.hpp:186
friend constexpr aarectangle intersect(aarectangle const &lhs, aarectangle const &rhs) noexcept
Return the overlapping part of two rectangles.
Definition aarectangle.hpp:478
static constexpr aarectangle large() noexcept
Create a large axis aligned rectangle.
Definition aarectangle.hpp:46
friend constexpr aarectangle operator*(aarectangle const &lhs, value_type rhs) noexcept
Expand the rectangle for the same amount in all directions.
Definition aarectangle.hpp:393
constexpr friend point2 midpoint(aarectangle const &rhs) noexcept
Get the center of the rectangle.
Definition aarectangle.hpp:247
constexpr aarectangle(extent2 const &extent) noexcept
Create a rectangle from the size.
Definition aarectangle.hpp:73
friend constexpr aarectangle operator-(aarectangle const &lhs, value_type rhs) noexcept
Shrink the rectangle for the same amount in all directions.
Definition aarectangle.hpp:426
constexpr bool empty() const noexcept
Check if the rectangle has no area.
Definition aarectangle.hpp:118
constexpr bool contains(point3 const &rhs) const noexcept
Check if a 3D coordinate is inside the rectangle.
Definition aarectangle.hpp:279
constexpr bool contains(point2 const &rhs) const noexcept
Check if a 2D coordinate is inside the rectangle.
Definition aarectangle.hpp:268
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:337
friend constexpr aarectangle floor(aarectangle const &rhs) noexcept
Round rectangle by shrinking to pixel edge.
Definition aarectangle.hpp:463
constexpr bool holds_invariant() const noexcept
Make sure p0 is left/bottom from p3.
Definition aarectangle.hpp:111
friend constexpr aarectangle align(aarectangle haystack, extent2 needle, alignment alignment) noexcept
Align a rectangle within another rectangle.
Definition aarectangle.hpp:291
friend constexpr aarectangle align(aarectangle haystack, aarectangle needle, alignment alignment) noexcept
Align a rectangle within another rectangle.
Definition aarectangle.hpp:330
friend constexpr aarectangle operator+(aarectangle const &lhs, value_type rhs) noexcept
Expand the rectangle for the same amount in all directions.
Definition aarectangle.hpp:410
constexpr value_type center() const noexcept
The center on the x-axis between left and right.
Definition aarectangle.hpp:240
constexpr aarectangle & operator|=(point2 const &rhs) noexcept
Expand the current rectangle to include the new rectangle.
Definition aarectangle.hpp:145
constexpr aarectangle(float x, float y, float width, float height) noexcept
Create a box from the position and size.
Definition aarectangle.hpp:63
friend constexpr aarectangle ceil(aarectangle const &rhs) noexcept
Round rectangle by expanding to pixel edge.
Definition aarectangle.hpp:445
constexpr aarectangle(point2 const &p0, point2 const &p3) noexcept
Create a rectangle from the left-bottom and right-top points.
Definition aarectangle.hpp:82
constexpr aarectangle & operator|=(aarectangle const &rhs) noexcept
Expand the current rectangle to include the new rectangle.
Definition aarectangle.hpp:135
constexpr value_type middle() const noexcept
The middle on the y-axis between bottom and top.
Definition aarectangle.hpp:233
constexpr aarectangle(point2 const &p0, extent2 const &extent) noexcept
Create a rectangle from the size.
Definition aarectangle.hpp:97
Horizontal/Vertical alignment combination.
Definition alignment.hpp:244
A high-level geometric extent.
Definition extent2.hpp:32
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector2.hpp:26
Definition simd_intf.hpp:18
T compare_exchange_weak(T... args)
T is_lock_free(T... args)