9#include "translate2.hpp"
10#include "translate3.hpp"
15#include "perspective.hpp"
23#include "rectangle.hpp"
28#include "../macros.hpp"
34hi_export_module(hikogui.geometry :
transform);
36hi_export
namespace hi {
inline namespace v1 {
71 return matrix2{lhs * get<0>(rhs), lhs * get<1>(rhs), lhs * get<2>(rhs), lhs * get<3>(rhs)};
78 return matrix3{lhs * get<0>(rhs), lhs * get<1>(rhs), lhs * get<2>(rhs), lhs * get<3>(rhs)};
81[[nodiscard]]
constexpr matrix2
operator*(translate2
const& lhs, matrix2
const& rhs)
noexcept
83 return matrix2{get<0>(rhs), get<1>(rhs), get<2>(rhs), get<3>(rhs) + f32x4{lhs}};
86[[nodiscard]]
constexpr matrix3
operator*(translate3
const& lhs, matrix3
const& rhs)
noexcept
88 return matrix3{get<0>(rhs), get<1>(rhs), get<2>(rhs), get<3>(rhs) + f32x4{lhs}};
91[[nodiscard]]
constexpr translate2
operator*(translate2
const& lhs, translate2
const& rhs)
noexcept
93 return translate2{f32x4{lhs} + f32x4{rhs}};
96[[nodiscard]]
constexpr translate3
operator*(translate3
const& lhs, translate3
const& rhs)
noexcept
98 return translate3{f32x4{lhs} + f32x4{rhs}};
101[[nodiscard]]
constexpr matrix2
operator*(translate2
const& lhs, scale2
const& rhs)
noexcept
103 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
104 return matrix2{f32x4{rhs}.x000(), f32x4{rhs}._0y00(), f32x4{rhs}._00z0(), f32x4{lhs}.xyz1()};
107[[nodiscard]]
constexpr matrix3
operator*(translate3
const& lhs, scale3
const& rhs)
noexcept
109 return matrix3{f32x4{rhs}.x000(), f32x4{rhs}._0y00(), f32x4{rhs}._00z0(), f32x4{lhs}.xyz1()};
112[[nodiscard]]
constexpr matrix2
operator*(translate2
const& lhs, rotate2
const& rhs)
noexcept
114 return lhs * matrix2(rhs);
117[[nodiscard]]
constexpr matrix3
operator*(translate3
const& lhs, rotate3
const& rhs)
noexcept
119 return lhs * matrix3(rhs);
122[[nodiscard]]
constexpr matrix2
operator*(scale2
const& lhs, translate2
const& rhs)
noexcept
124 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
125 return matrix2{f32x4{lhs}.x000(), f32x4{lhs}._0y00(), f32x4{lhs}._00z0(), f32x4{lhs} * f32x4{rhs}.xyz1()};
128[[nodiscard]]
constexpr matrix3
operator*(scale3
const& lhs, translate3
const& rhs)
noexcept
130 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
131 return matrix3{f32x4{lhs}.x000(), f32x4{lhs}._0y00(), f32x4{lhs}._00z0(), f32x4{lhs} * f32x4{rhs}.xyz1()};
134[[nodiscard]]
constexpr scale2
operator*(scale2
const& lhs, scale2
const& rhs)
noexcept
136 return scale2{f32x4{lhs} * f32x4{rhs}};
139[[nodiscard]]
constexpr scale3
operator*(scale3
const& lhs, scale3
const& rhs)
noexcept
141 return scale3{f32x4{lhs} * f32x4{rhs}};
154 auto const abs_scale = hypot<0b0011>(get<0>(lhs) * f32x4::broadcast(rhs)).x();
168 auto const abs_scale = hypot<0b0111>(get<0>(lhs) * f32x4::broadcast(rhs)).x();
174[[nodiscard]]
constexpr float operator*(translate2
const&,
float const& rhs)
noexcept
179[[nodiscard]]
constexpr float operator*(translate3
const&,
float const& rhs)
noexcept
184[[nodiscard]]
constexpr float operator*(scale2
const& lhs,
float const& rhs)
noexcept
186 return lhs.x() * rhs;
189[[nodiscard]]
constexpr float operator*(scale3
const& lhs,
float const& rhs)
noexcept
191 return lhs.x() * rhs;
194[[nodiscard]]
constexpr float operator*(rotate2
const&,
float const& rhs)
noexcept
199[[nodiscard]]
constexpr float operator*(rotate3
const&,
float const& rhs)
noexcept
213 return vector2{get<0>(lhs) *
f32x4{rhs}.xxxx() + get<1>(lhs) *
f32x4{rhs}.yyyy()};
216[[nodiscard]]
constexpr vector2
operator*(translate2
const&, vector2
const& rhs)
noexcept
221[[nodiscard]]
constexpr vector2
operator*(translate3
const&, vector2
const& rhs)
noexcept
226[[nodiscard]]
constexpr vector2
operator*(scale2
const& lhs, vector2
const& rhs)
noexcept
228 return vector2{f32x4{lhs} * f32x4{rhs}};
231[[nodiscard]]
constexpr vector2
operator*(scale3
const& lhs, vector2
const& rhs)
noexcept
233 return vector2{f32x4{lhs} * f32x4{rhs}};
245 return vector3{get<0>(lhs) *
f32x4{rhs}.xxxx() + get<1>(lhs) *
f32x4{rhs}.yyyy() + get<2>(lhs) *
f32x4{rhs}.zzzz()};
248[[nodiscard]]
constexpr vector3
operator*(translate3
const&, vector3
const& rhs)
noexcept
253[[nodiscard]]
constexpr vector3
operator*(scale3
const& lhs, vector3
const& rhs)
noexcept
255 return vector3{f32x4{lhs} * f32x4{rhs}};
265 return point2{get<0>(lhs) *
f32x4{rhs}.xxxx() + get<1>(lhs) *
f32x4{rhs}.yyyy() + get<3>(lhs)};
268[[nodiscard]]
constexpr point2
operator*(translate2
const& lhs, point2
const& rhs)
noexcept
270 return point2{f32x4{lhs} + f32x4{rhs}};
273[[nodiscard]]
constexpr point2
operator*(scale2
const& lhs, point2
const& rhs)
noexcept
275 return point2{f32x4{lhs} * f32x4{rhs}};
278[[nodiscard]]
constexpr point2
operator*(scale3
const& lhs, point2
const& rhs)
noexcept
280 return point2{f32x4{lhs} * f32x4{rhs}};
291 get<0>(lhs) *
f32x4{rhs}.xxxx() + get<1>(lhs) *
f32x4{rhs}.yyyy() + get<2>(lhs) *
f32x4{rhs}.zzzz() +
292 get<3>(lhs) *
f32x4{rhs}.wwww()};
295[[nodiscard]]
constexpr point3
operator*(translate3
const& lhs, point3
const& rhs)
noexcept
297 return point3{f32x4{lhs} + f32x4{rhs}};
300[[nodiscard]]
constexpr point3
operator*(scale3
const& lhs, point3
const& rhs)
noexcept
302 return point3{f32x4{lhs} * f32x4{rhs}};
305[[nodiscard]]
constexpr extent2
operator*(transformer2
auto const& lhs, extent2
const& rhs)
noexcept
307 return extent2{lhs *vector2{rhs}};
310[[nodiscard]]
constexpr extent3
operator*(transformer3
auto const& lhs, std::convertible_to<extent3>
auto const& rhs)
noexcept
312 return extent3{lhs *vector3{rhs}};
315[[nodiscard]]
constexpr aarectangle
operator*(translate2
const& lhs, aarectangle
const& rhs)
noexcept
317 return aarectangle{lhs * get<0>(rhs), lhs * get<3>(rhs)};
324 return aarectangle{lhs * get<0>(rhs), lhs * get<3>(rhs)};
339 return rectangle{lhs * rhs_.origin, lhs * rhs_.right, lhs * rhs_.up};
348[[deprecated(
"Use full_mul() or fast_mul() instead.")]] [[nodiscard]]
constexpr rectangle
352 return rectangle{lhs * rhs_.origin, lhs * rhs_.right, lhs * rhs_.up};
364 return rectangle{lhs * rhs_.origin, lhs * rhs_.right, lhs * rhs_.up};
375 return aarectangle{lhs * get<0>(rhs), lhs * get<3>(rhs)};
386 return rectangle{lhs * rhs.origin, lhs * rhs.right, lhs * rhs.up};
394[[nodiscard]]
constexpr quad
operator*(transformer
auto const& lhs, quad
const& rhs)
noexcept
396 return quad{lhs * rhs.p0, lhs * rhs.p1, lhs * rhs.p2, lhs * rhs.p3};
406 return circle{lhs * midpoint(rhs), lhs * rhs.radius()};
416 return line_segment{lhs * rhs.origin(), lhs * rhs.direction()};
426 return {lhs * get<0>(rhs), lhs * get<1>(rhs), lhs * get<2>(rhs), lhs * get<3>(rhs)};
435template<
typename Lhs, transformer Rhs>
437 requires requires(Lhs& a, Rhs
const& b) { a = b * a; }
439 return lhs = rhs * lhs;
442[[nodiscard]]
constexpr aarectangle fit(aarectangle
const& bounds, aarectangle
const&
rectangle)
noexcept
444 auto const resized_rectangle = aarectangle{
450 auto const translate_from_p0 = max(vector2{}, get<0>(bounds) - get<0>(resized_rectangle));
451 auto const translate_from_p3 = min(vector2{}, get<3>(bounds) - get<3>(resized_rectangle));
452 return translate2{translate_from_p0 + translate_from_p3} * resized_rectangle;
465 auto const top_extra = (lhs.top() * rhs.x() - lhs.top()) * 0.5f;
466 auto const bottom_extra = (lhs.bottom() * rhs.x() - lhs.bottom()) * 0.5f;
467 auto const left_extra = (lhs.left() * rhs.y() - lhs.left()) * 0.5f;
468 auto const right_extra = (lhs.right() * rhs.y() - lhs.right()) * 0.5f;
471 lhs.p0 - bottom_extra - left_extra,
472 lhs.p1 + bottom_extra - right_extra,
473 lhs.p2 - top_extra + left_extra,
474 lhs.p3 + top_extra + right_extra};
Defined the corner_radii type.
Defined the geo::extent, extent2 and extent3 types.
Defined the geo::extent, extent2 and extent3 types.
@ rectangle
The gui_event has rectangle data.
The HikoGUI namespace.
Definition array_generic.hpp:20
constexpr aarectangle fast_mul(matrix2 const &lhs, aarectangle const &rhs) noexcept
Transform an axis-aligned rectangle without rotation by the matrix.
Definition transform.hpp:373
constexpr rectangle full_mul(matrix2 const &lhs, aarectangle const &rhs) noexcept
Transform an axis-aligned rectangle without rotation by the matrix.
Definition transform.hpp:361
constexpr Lhs & operator*=(Lhs &lhs, Rhs const &rhs) noexcept
Inplace geometric translation.
Definition transform.hpp:436
constexpr matrix2 operator*(matrix2 const &lhs, matrix2 const &rhs) noexcept
Matrix/Matrix multiplication.
Definition transform.hpp:69
constexpr quad scale_from_center(quad const &lhs, scale2 const &rhs) noexcept
scale the quad.
Definition transform.hpp:463
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition simd_intf.hpp:18
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
A type defining a 2D circle.
Definition circle.hpp:23
The 4 radii of the corners of a quad or rectangle.
Definition corner_radii.hpp:26
Line segment.
Definition line_segment.hpp:26
A 2D or 3D homogenius matrix for transforming homogenious vectors and points.
Definition matrix2.hpp:39
A 2D or 3D homogenius matrix for transforming homogenious vectors and points.
Definition matrix3.hpp:36
Perspective transform.
Definition perspective.hpp:21
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:25
Definition rotate2.hpp:17
Definition rotate3.hpp:17
Definition transform.hpp:39
Definition transform.hpp:41
Definition translate2.hpp:18
Definition translate3.hpp:22
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector2.hpp:27
A high-level geometric vector Part of the high-level vector, point, mat and color types.
Definition vector3.hpp:26
Definition transform.hpp:61
Definition transform.hpp:63
Definition transform.hpp:65