9#include "../macros.hpp"
10#include <hikocpu/hikocpu.hpp>
15hi_export_module(hikogui.geometry :
rectangle);
17hi_export
namespace hi {
inline namespace v1 {
31 constexpr rectangle() noexcept : origin(), right(), up() {}
52 constexpr rectangle(point3 origin, point3 right_bottom, point3 left_top, point3 right_top) noexcept :
53 rectangle(origin, right_bottom - origin, left_top - origin)
59 auto const p0 = get<0>(rhs);
60 auto const p3 = get<3>(rhs);
61 auto const diagonal =
static_cast<f32x4>(p3 - p0);
64 right =
vector3{diagonal.x000()};
68 constexpr explicit rectangle(extent2
size) noexcept :
73 constexpr rectangle& operator=(aarectangle rhs)
noexcept
75 auto const p0 = get<0>(rhs);
76 auto const p3 = get<3>(rhs);
77 auto const diagonal =
static_cast<f32x4
>(p3 - p0);
80 right = vector3{diagonal.x000()};
81 up = vector3{diagonal._0y00()};
85 constexpr rectangle(point3 origin, extent2 extent) noexcept : rectangle(origin, extent.right(), extent.up()) {}
94 auto const p0 = rhs.origin;
95 left_bottom = min(left_bottom,
static_cast<f32x4>(p0));
96 right_top = max(right_top,
static_cast<f32x4>(p0));
98 auto const p1 = p0 + rhs.right;
99 left_bottom = min(left_bottom,
static_cast<f32x4>(p1));
100 right_top = max(right_top,
static_cast<f32x4>(p1));
102 auto const p2 = p0 + rhs.up;
103 left_bottom = min(left_bottom,
static_cast<f32x4>(p2));
104 right_top = max(right_top,
static_cast<f32x4>(p2));
106 auto const p3 = p2 + rhs.right;
107 left_bottom = min(left_bottom,
static_cast<f32x4>(p3));
108 right_top = max(right_top,
static_cast<f32x4>(p3));
110 return aarectangle{left_bottom.xy00() | right_top._00xy()};
117 [[nodiscard]]
explicit operator bool() const noexcept
129 auto const dp = dot(right, up);
139 auto const should_be_zeroes =
static_cast<f32x4>(right).yz00() |
static_cast<f32x4>(up)._00xz();
140 return equal(should_be_zeroes,
f32x4{});
145 [[nodiscard]]
float width() const noexcept
152 [[nodiscard]]
float height() const noexcept
164 [[nodiscard]]
float area() const noexcept
166 return hypot(cross(right, up));
169 [[nodiscard]]
constexpr point3 operator[](
std::size_t i)
const noexcept
173 return get<0>(*
this);
175 return get<1>(*
this);
177 return get<2>(*
this);
179 return get<3>(*
this);
185 template<std::
size_t I>
186 [[nodiscard]]
friend constexpr point3 get(rectangle
const& rhs)
noexcept
188 static_assert(I < 4);
189 if constexpr (I == 0) {
191 }
else if constexpr (I == 1) {
192 return rhs.origin + rhs.right;
193 }
else if constexpr (I == 2) {
194 return rhs.origin + rhs.up;
196 return rhs.origin + rhs.right + rhs.up;
215 auto const extra_right = normalize(lhs.right) * rhs.
width();
216 auto const extra_up = normalize(lhs.up) * rhs.
height();
217 auto const extra_diagonal = extra_right + extra_up;
219 return rectangle{lhs.origin - extra_diagonal, lhs.right + 2.0f * extra_right, lhs.up + 2.0f * extra_up};
237 auto const extra_right = normalize(lhs.right) * rhs.
width();
238 auto const extra_up = normalize(lhs.up) * rhs.
height();
239 auto const extra_diagonal = extra_right + extra_up;
241 return rectangle{lhs.origin + extra_diagonal, lhs.right - 2.0f * extra_right, lhs.up - 2.0f * extra_up};
259 return lhs +
extent2{rhs, rhs};
277 return lhs -
extent2{rhs, rhs};
types and utilities for alignment.
@ rectangle
The gui_event has rectangle data.
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
A high-level geometric extent.
Definition extent2.hpp:32
constexpr float & width() noexcept
Access the x-as-width element from the extent.
Definition extent2.hpp:107
constexpr float & height() noexcept
Access the y-as-height element from the extent.
Definition extent2.hpp:118
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:25
constexpr bool is_axis_aligned() const noexcept
Check if this is an axis aligned rectangle.
Definition rectangle.hpp:137
float height() const noexcept
The height, or length of the up vector.
Definition rectangle.hpp:152
friend constexpr rectangle operator-(rectangle const &lhs, float rhs) noexcept
Shrink the rectangle by subtracting an absolute distance from each side.
Definition rectangle.hpp:275
friend constexpr rectangle operator-(rectangle const &lhs, extent2 rhs) noexcept
Shrink the rectangle by subtracting an absolute distance from each side.
Definition rectangle.hpp:235
friend constexpr rectangle operator+(rectangle const &lhs, extent2 rhs) noexcept
Expand the rectangle by adding an absolute distance on each side.
Definition rectangle.hpp:213
constexpr friend aarectangle bounding_rectangle(rectangle const &rhs) noexcept
Return the axis-aligned bounding rectangle of this rectangle.
Definition rectangle.hpp:89
friend constexpr rectangle operator+(rectangle const &lhs, float rhs) noexcept
Expand the rectangle by adding an absolute distance on each side.
Definition rectangle.hpp:257
constexpr rectangle(point3 origin, point3 right_bottom, point3 left_top, point3 right_top) noexcept
Create a rectangle from 4 corner points.
Definition rectangle.hpp:52
float width() const noexcept
The width, or length of the right vector.
Definition rectangle.hpp:145
constexpr extent2 size() const noexcept
The size, or length of the right and up vectors.
Definition rectangle.hpp:159
constexpr bool is_rectangle() const noexcept
Check if this is a rectangle.
Definition rectangle.hpp:127
constexpr rectangle(point3 origin, vector3 right, vector3 up) noexcept
Create a rectangle from a corner point and two vectors.
Definition rectangle.hpp:43
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:26