9#include "../SIMD/module.hpp"
12namespace hi {
inline namespace v1 {
26 constexpr rectangle() noexcept : origin(), right(), up() {}
47 constexpr rectangle(point3 origin, point3 right_bottom, point3 left_top, point3 right_top) noexcept :
48 rectangle(origin, right_bottom - origin, left_top - origin)
54 hilet p0 = get<0>(rhs);
55 hilet p3 = get<3>(rhs);
56 hilet diagonal =
static_cast<f32x4
>(p3 - p0);
59 right =
vector3{diagonal.x000()};
63 constexpr explicit rectangle(extent2
size) noexcept :
68 constexpr rectangle& operator=(aarectangle rhs)
noexcept
70 hilet p0 = get<0>(rhs);
71 hilet p3 = get<3>(rhs);
72 hilet diagonal =
static_cast<f32x4
>(p3 - p0);
75 right = vector3{diagonal.x000()};
76 up = vector3{diagonal._0y00()};
80 constexpr rectangle(point3 origin, extent2 extent) noexcept : rectangle(origin, extent.right(), extent.up()) {}
84 [[nodiscard]]
constexpr explicit operator aarectangle() const noexcept
90 left_bottom = min(left_bottom,
static_cast<f32x4
>(p0));
91 right_top = max(right_top,
static_cast<f32x4
>(p0));
93 hilet p1 = p0 + right;
94 left_bottom = min(left_bottom,
static_cast<f32x4
>(p1));
95 right_top = max(right_top,
static_cast<f32x4
>(p1));
98 left_bottom = min(left_bottom,
static_cast<f32x4
>(p2));
99 right_top = max(right_top,
static_cast<f32x4
>(p2));
101 hilet p3 = p2 + right;
102 left_bottom = min(left_bottom,
static_cast<f32x4
>(p3));
103 right_top = max(right_top,
static_cast<f32x4
>(p3));
105 return aarectangle{left_bottom.xy00() | right_top._00xy()};
112 [[nodiscard]]
explicit operator bool() const noexcept
124 hilet dp = dot(right, up);
134 hilet should_be_zeroes =
static_cast<f32x4
>(right).yz00() |
static_cast<f32x4
>(up)._00xz();
135 return equal(should_be_zeroes, f32x4{});
140 [[nodiscard]]
float width() const noexcept
147 [[nodiscard]]
float height() const noexcept
159 [[nodiscard]]
float area() const noexcept
161 return hypot(cross(right, up));
164 [[nodiscard]]
constexpr point3 operator[](
std::size_t i)
const noexcept
168 return get<0>(*
this);
170 return get<1>(*
this);
172 return get<2>(*
this);
174 return get<3>(*
this);
180 template<std::
size_t I>
181 [[nodiscard]]
friend constexpr point3 get(rectangle
const& rhs)
noexcept
183 static_assert(I < 4);
184 if constexpr (I == 0) {
186 }
else if constexpr (I == 1) {
187 return rhs.origin + rhs.right;
188 }
else if constexpr (I == 2) {
189 return rhs.origin + rhs.up;
191 return rhs.origin + rhs.right + rhs.up;
210 hilet extra_right = normalize(lhs.right) * rhs.
width();
212 hilet extra_diagonal = extra_right + extra_up;
214 return rectangle{lhs.origin - extra_diagonal, lhs.right + 2.0f * extra_right, lhs.up + 2.0f * extra_up};
232 hilet extra_right = normalize(lhs.right) * rhs.
width();
234 hilet extra_diagonal = extra_right + extra_up;
236 return rectangle{lhs.origin + extra_diagonal, lhs.right - 2.0f * extra_right, lhs.up - 2.0f * extra_up};
254 return lhs +
extent2{rhs, rhs};
272 return lhs -
extent2{rhs, rhs};
types and utilities for alignment.
#define hi_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:279
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:26
A high-level geometric extent.
Definition extent2.hpp:26
constexpr float & width() noexcept
Access the x-as-width element from the extent.
Definition extent2.hpp:101
constexpr float & height() noexcept
Access the y-as-height element from the extent.
Definition extent2.hpp:112
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:20
constexpr bool is_axis_aligned() const noexcept
Check if this is an axis aligned rectangle.
Definition rectangle.hpp:132
float height() const noexcept
The height, or length of the up vector.
Definition rectangle.hpp:147
friend constexpr rectangle operator-(rectangle const &lhs, float rhs) noexcept
Shrink the rectangle by subtracting an absolute distance from each side.
Definition rectangle.hpp:270
friend constexpr rectangle operator-(rectangle const &lhs, extent2 rhs) noexcept
Shrink the rectangle by subtracting an absolute distance from each side.
Definition rectangle.hpp:230
friend constexpr rectangle operator+(rectangle const &lhs, extent2 rhs) noexcept
Expand the rectangle by adding an absolute distance on each side.
Definition rectangle.hpp:208
friend constexpr rectangle operator+(rectangle const &lhs, float rhs) noexcept
Expand the rectangle by adding an absolute distance on each side.
Definition rectangle.hpp:252
constexpr rectangle(point3 origin, point3 right_bottom, point3 left_top, point3 right_top) noexcept
Create a rectangle from 4 corner points.
Definition rectangle.hpp:47
float width() const noexcept
The width, or length of the right vector.
Definition rectangle.hpp:140
constexpr extent2 size() const noexcept
The size, or length of the right and up vectors.
Definition rectangle.hpp:154
constexpr bool is_rectangle() const noexcept
Check if this is a rectangle.
Definition rectangle.hpp:122
constexpr rectangle(point3 origin, vector3 right, vector3 up) noexcept
Create a rectangle from a corner point and two vectors.
Definition rectangle.hpp:38
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:19