6#include "TTauri/Foundation/ivec.hpp"
21 tt_force_inline
iaarect() noexcept : v() {}
23 tt_force_inline
iaarect &operator=(
iaarect const &rhs)
noexcept =
default;
25 tt_force_inline
iaarect &operator=(
iaarect &&rhs)
noexcept =
default;
30 iaarect &operator=(__m128i rhs)
noexcept {
35 operator __m128i ()
const noexcept {
46 template<
typename T, std::enable_if_t<std::is_
integral_v<T>,
int> = 0>
47 tt_force_inline
iaarect(T x, T y, T width, T height) noexcept :
58 [[nodiscard]] tt_force_inline
static iaarect p0p3(
ivec const &p1,
ivec const &p2)
noexcept {
59 return _mm_blend_epi16(p1, p2.xyxy(), 0b11'11'00'00);
68 return *
this = *
this | rhs;
76 return *
this = *
this + rhs;
84 return *
this = *
this - rhs;
93 [[nodiscard]] tt_force_inline
ivec corner() const noexcept {
94 static_assert(I <= 3);
95 if constexpr (I == 0) {
97 }
else if constexpr (I == 1) {
99 }
else if constexpr (I == 2) {
110 [[nodiscard]] tt_force_inline
ivec offset() const noexcept {
return corner<0>(); }
118 return corner<3>() - corner<0>();
121 [[nodiscard]] tt_force_inline
int x1() const noexcept {
return v.x(); }
122 [[nodiscard]] tt_force_inline
int y1() const noexcept {
return v.y(); }
123 [[nodiscard]] tt_force_inline
int x2() const noexcept {
return v.z(); }
124 [[nodiscard]] tt_force_inline
int y2() const noexcept {
return v.w(); }
125 [[nodiscard]] tt_force_inline
int width() const noexcept {
return extent().x(); }
126 [[nodiscard]] tt_force_inline
int height() const noexcept {
return extent().y(); }
134 (((rhs >= v) & 0x00ff) == 0x00ff) &&
135 (((rhs <= v) & 0xff00) == 0xff00);
138 [[nodiscard]]
friend bool operator==(
iaarect const &lhs,
iaarect const &rhs)
noexcept {
139 return lhs.v == rhs.v;
142 [[nodiscard]]
friend bool operator!=(iaarect
const &lhs, iaarect
const &rhs)
noexcept {
143 return !(lhs == rhs);
146 [[nodiscard]]
friend iaarect operator|(iaarect
const &lhs, iaarect
const &rhs)
noexcept {
147 return _mm_blend_epi16(
min(lhs.v, rhs.v),
max(lhs.v, rhs.v), 0b11'11'00'00);
150 [[nodiscard]]
friend iaarect operator+(iaarect
const &lhs, ivec
const &rhs)
noexcept {
151 return static_cast<__m128i
>(lhs.v + rhs.xyxy());
154 [[nodiscard]]
friend iaarect operator-(iaarect
const &lhs, ivec
const &rhs)
noexcept {
155 return static_cast<__m128i
>(lhs.v - rhs.xyxy());
164 template<
typename T, std::enable_if_t<std::is_
integral_v<T>,
int> = 0>
166 ttlet _0000 = _mm_setzero_si128();
167 ttlet _000r = _mm_insert_epi32(_0000, rhs, 0);
168 ttlet _00rr =
ivec{_mm_shuffle_epi32(_000r, _MM_SHUFFLE(1,1,0,0))};
169 ttlet _rr00 =
ivec{_mm_shuffle_epi32(_000r, _MM_SHUFFLE(0,0,1,1))};
170 return static_cast<__m128i
>((lhs.v - _00rr) + _rr00);
Class which represents an axis-aligned rectangle.
Definition iaarect.hpp:12
tt_force_inline ivec offset() const noexcept
Get coordinate of the bottom-left corner.
Definition iaarect.hpp:110
ivec extent() const noexcept
Get size of the rectangle.
Definition iaarect.hpp:117
tt_force_inline iaarect(ivec const &offset, ivec const &extent) noexcept
Create a box from the position and size.
Definition iaarect.hpp:55
bool contains(ivec const &rhs) const noexcept
Check if a 2D coordinate is inside the rectangle.
Definition iaarect.hpp:132
tt_force_inline iaarect(T x, T y, T width, T height) noexcept
Create a box from the position and size.
Definition iaarect.hpp:47
iaarect & operator-=(ivec const &rhs) noexcept
Translate the box to a new position.
Definition iaarect.hpp:83
iaarect & operator|=(iaarect const &rhs) noexcept
Expand the current rectangle to include the new rectangle.
Definition iaarect.hpp:67
tt_force_inline ivec corner() const noexcept
Get coordinate of a corner.
Definition iaarect.hpp:93
friend iaarect expand(iaarect const &lhs, T rhs) noexcept
Expand the rectangle for the same amount in all directions.
Definition iaarect.hpp:165
iaarect & operator+=(ivec const &rhs) noexcept
Translate the box to a new position.
Definition iaarect.hpp:75
A 4D vector.
Definition ivec.hpp:37