8#include "axis_aligned_rectangle.hpp"
9#include "rectangle.hpp"
12namespace hi::inline v1 {
21 constexpr quad() noexcept : p0(), p1(), p2(), p3() {}
25 constexpr quad(quad
const &)
noexcept =
default;
26 constexpr quad(quad &&) noexcept = default;
27 constexpr quad &operator=(quad const &) noexcept = default;
28 constexpr quad &operator=(quad &&) noexcept = default;
30 constexpr quad(aarectangle const &rhs) noexcept
32 hilet tmp = f32x4{rhs};
33 p0 = point3{tmp.xy01()};
34 p1 = point3{tmp.zy01()};
35 p2 = point3{tmp.xw01()};
36 p3 = point3{tmp.zw01()};
39 constexpr quad(rectangle
const &rhs) noexcept : p0(get<0>(rhs)), p1(get<1>(rhs)), p2(get<2>(rhs)), p3(get<3>(rhs)) {}
76 return sqrt(x * x + y * y + z * z);
86 default: hi_no_default();
90 [[nodiscard]]
constexpr point3
const &operator[](
std::size_t index)
const noexcept
97 default: hi_no_default();
101 template<std::
size_t I>
102 [[nodiscard]]
constexpr friend point3
const &get(quad
const &rhs)
noexcept
104 static_assert(I < 4,
"Index out of range.");
106 if constexpr (I == 0) {
108 }
else if constexpr (I == 1) {
110 }
else if constexpr (I == 2) {
117 template<std::
size_t I>
118 [[nodiscard]]
constexpr friend point3 &get(quad &rhs)
noexcept
120 static_assert(I < 4,
"Index out of range.");
122 if constexpr (I == 0) {
124 }
else if constexpr (I == 1) {
126 }
else if constexpr (I == 2) {
148 hilet[x, y, z, ones] = transpose(t, l, b, r);
149 hilet square_lengths = x * x + y * y + z * z;
150 hilet inv_lengths = rcp_sqrt(square_lengths);
151 hilet norm_t = t * inv_lengths.xxxx();
152 hilet norm_l = l * inv_lengths.yyyy();
153 hilet norm_b = b * inv_lengths.zzzz();
154 hilet norm_r = r * inv_lengths.wwww();
156 hilet width = rhs.xxxx();
157 hilet height = rhs.yyyy();
164 hilet lengths = rcp(inv_lengths);
166 hilet rhs_times_2 = rhs + rhs;
170 lhs.
p0 - bottom_extra - left_extra,
171 lhs.p1 + bottom_extra - right_extra,
172 lhs.p2 - top_extra + left_extra,
173 lhs.p3 + top_extra + right_extra},
174 lengths + rhs_times_2.xyxy()};
187 return expand_and_edge_hypots(lhs,
f32x4{rhs});
200 return expand_and_edge_hypots(lhs, -
f32x4{rhs});
213 hilet[expanded_quad, new_lengths] = expand_and_edge_hypots(lhs, rhs);
214 return expanded_quad;
217 [[nodiscard]]
friend constexpr quad operator+(
quad const &lhs,
float rhs)
noexcept
219 return lhs +
extent2{rhs, rhs};
232 hilet[expanded_quad, new_lengths] = shrink_and_edge_hypots(lhs, rhs);
233 return expanded_quad;
236 [[nodiscard]]
friend constexpr quad operator-(
quad const &lhs,
float rhs)
noexcept
238 return lhs -
extent2{rhs, rhs};
241 [[nodiscard]]
friend constexpr aarectangle bounding_rectangle(quad
const &rhs)
noexcept
246 min_p =
min(min_p, rhs.p1);
247 max_p =
max(max_p, rhs.p1);
248 min_p =
min(min_p, rhs.p2);
249 max_p =
max(max_p, rhs.p2);
250 min_p =
min(min_p, rhs.p3);
251 max_p =
max(max_p, rhs.p3);
252 return aarectangle{point2{min_p}, point2{max_p}};
255 constexpr quad &operator+=(extent2
const &rhs)
noexcept
257 return *
this = *
this + rhs;
260 [[nodiscard]]
friend constexpr bool operator==(quad
const &lhs, quad
const &rhs)
noexcept =
default;
#define hilet
Invariant should be the default for variables.
Definition required.hpp:23
@ bottom
Align to the bottom.
friend constexpr std::pair< quad, f32x4 > expand_and_edge_hypots(quad const &lhs, f32x4 const &rhs) noexcept
Add a border around the quad.
Definition quad.hpp:141
point3 p3
Right-top.
Definition quad.hpp:19
constexpr vector3 right() const noexcept
The vector from right-bottom to right-top.
Definition quad.hpp:64
friend constexpr std::pair< quad, f32x4 > shrink_and_edge_hypots(quad const &lhs, extent2 const &rhs) noexcept
Subtract a border from the quad.
Definition quad.hpp:198
point3 p1
Right-bottom.
Definition quad.hpp:17
friend constexpr quad operator+(quad const &lhs, extent2 const &rhs) noexcept
Add a border around the quad.
Definition quad.hpp:211
constexpr vector3 left() const noexcept
The vector from left-bottom to left-top.
Definition quad.hpp:57
friend constexpr quad operator-(quad const &lhs, extent2 const &rhs) noexcept
Add a border around the quad.
Definition quad.hpp:230
point3 p0
Left-bottom.
Definition quad.hpp:16
constexpr vector3 bottom() const noexcept
The vector from left-bottom to right-bottom.
Definition quad.hpp:43
constexpr vector3 top() const noexcept
The vector from left-top to right-top.
Definition quad.hpp:50
point3 p2
Left-top.
Definition quad.hpp:18
constexpr f32x4 edge_hypots() const noexcept
Return the length of each edge.
Definition quad.hpp:73
friend constexpr std::pair< quad, f32x4 > expand_and_edge_hypots(quad const &lhs, extent2 const &rhs) noexcept
Add a border around the quad.
Definition quad.hpp:185