9#include "../SIMD/module.hpp"
10#include "../macros.hpp"
13namespace hi {
inline namespace v1 {
27 constexpr rectangle() noexcept : origin(), right(), up() {}
48 constexpr rectangle(point3 origin, point3 right_bottom, point3 left_top, point3 right_top) noexcept :
49 rectangle(origin, right_bottom - origin, left_top - origin)
55 hilet p0 = get<0>(rhs);
56 hilet p3 = get<3>(rhs);
57 hilet diagonal =
static_cast<f32x4
>(p3 - p0);
60 right =
vector3{diagonal.x000()};
64 constexpr explicit rectangle(extent2
size) noexcept :
65 rectangle(point3{}, vector3{
size.width(), 0.0f, 0.0f}, vector3{0.0f,
size.height(), 0.0f})
69 constexpr rectangle& operator=(aarectangle rhs)
noexcept
71 hilet p0 = get<0>(rhs);
72 hilet p3 = get<3>(rhs);
73 hilet diagonal =
static_cast<f32x4
>(p3 - p0);
76 right = vector3{diagonal.x000()};
77 up = vector3{diagonal._0y00()};
81 constexpr rectangle(point3 origin, extent2 extent) noexcept : rectangle(origin, extent.right(), extent.up()) {}
90 hilet p0 = rhs.origin;
91 left_bottom = min(left_bottom,
static_cast<f32x4
>(p0));
92 right_top = max(right_top,
static_cast<f32x4
>(p0));
94 hilet p1 = p0 + rhs.right;
95 left_bottom = min(left_bottom,
static_cast<f32x4
>(p1));
96 right_top = max(right_top,
static_cast<f32x4
>(p1));
98 hilet p2 = p0 + rhs.up;
99 left_bottom = min(left_bottom,
static_cast<f32x4
>(p2));
100 right_top = max(right_top,
static_cast<f32x4
>(p2));
102 hilet p3 = p2 + rhs.right;
103 left_bottom = min(left_bottom,
static_cast<f32x4
>(p3));
104 right_top = max(right_top,
static_cast<f32x4
>(p3));
106 return aarectangle{left_bottom.xy00() | right_top._00xy()};
113 [[nodiscard]]
explicit operator bool() const noexcept
125 hilet dp = dot(right, up);
135 hilet should_be_zeroes =
static_cast<f32x4
>(right).yz00() |
static_cast<f32x4
>(up)._00xz();
136 return equal(should_be_zeroes, f32x4{});
141 [[nodiscard]]
float width() const noexcept
148 [[nodiscard]]
float height() const noexcept
160 [[nodiscard]]
float area() const noexcept
162 return hypot(cross(right, up));
165 [[nodiscard]]
constexpr point3 operator[](
std::size_t i)
const noexcept
169 return get<0>(*
this);
171 return get<1>(*
this);
173 return get<2>(*
this);
175 return get<3>(*
this);
181 template<std::
size_t I>
182 [[nodiscard]]
friend constexpr point3 get(rectangle
const& rhs)
noexcept
184 static_assert(I < 4);
185 if constexpr (I == 0) {
187 }
else if constexpr (I == 1) {
188 return rhs.origin + rhs.right;
189 }
else if constexpr (I == 2) {
190 return rhs.origin + rhs.up;
192 return rhs.origin + rhs.right + rhs.up;
209 [[nodiscard]]
friend constexpr rectangle
operator+(rectangle
const& lhs,
extent2 rhs)
noexcept
211 hilet extra_right = normalize(lhs.right) * rhs.
width();
212 hilet extra_up = normalize(lhs.up) * rhs.
height();
213 hilet extra_diagonal = extra_right + extra_up;
215 return rectangle{lhs.origin - extra_diagonal, lhs.right + 2.0f * extra_right, lhs.up + 2.0f * extra_up};
231 [[nodiscard]]
friend constexpr rectangle
operator-(rectangle
const& lhs,
extent2 rhs)
noexcept
233 hilet extra_right = normalize(lhs.right) * rhs.
width();
234 hilet extra_up = normalize(lhs.up) * rhs.
height();
235 hilet extra_diagonal = extra_right + extra_up;
237 return rectangle{lhs.origin + extra_diagonal, lhs.right - 2.0f * extra_right, lhs.up - 2.0f * extra_up};
253 [[nodiscard]]
friend constexpr rectangle
operator+(rectangle
const& lhs,
float rhs)
noexcept
255 return lhs +
extent2{rhs, rhs};
271 [[nodiscard]]
friend constexpr rectangle
operator-(rectangle
const& lhs,
float rhs)
noexcept
273 return lhs -
extent2{rhs, rhs};
types and utilities for alignment.
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
The HikoGUI API version 1.
Definition lookahead_iterator.hpp:6
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
A high-level geometric extent.
Definition extent2.hpp:29
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:21
constexpr bool is_axis_aligned() const noexcept
Check if this is an axis aligned rectangle.
Definition rectangle.hpp:133
float height() const noexcept
The height, or length of the up vector.
Definition rectangle.hpp:148
friend constexpr rectangle operator-(rectangle const &lhs, float rhs) noexcept
Shrink the rectangle by subtracting an absolute distance from each side.
Definition rectangle.hpp:271
friend constexpr rectangle operator-(rectangle const &lhs, extent2 rhs) noexcept
Shrink the rectangle by subtracting an absolute distance from each side.
Definition rectangle.hpp:231
friend constexpr rectangle operator+(rectangle const &lhs, extent2 rhs) noexcept
Expand the rectangle by adding an absolute distance on each side.
Definition rectangle.hpp:209
constexpr friend aarectangle bounding_rectangle(rectangle const &rhs) noexcept
Return the axis-aligned bounding rectangle of this rectangle.
Definition rectangle.hpp:85
friend constexpr rectangle operator+(rectangle const &lhs, float rhs) noexcept
Expand the rectangle by adding an absolute distance on each side.
Definition rectangle.hpp:253
constexpr rectangle(point3 origin, point3 right_bottom, point3 left_top, point3 right_top) noexcept
Create a rectangle from 4 corner points.
Definition rectangle.hpp:48
float width() const noexcept
The width, or length of the right vector.
Definition rectangle.hpp:141
constexpr extent2 size() const noexcept
The size, or length of the right and up vectors.
Definition rectangle.hpp:155
constexpr bool is_rectangle() const noexcept
Check if this is a rectangle.
Definition rectangle.hpp:123
constexpr rectangle(point3 origin, vector3 right, vector3 up) noexcept
Create a rectangle from a corner point and two vectors.
Definition rectangle.hpp:39
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:20