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}};
88 return matrix3{get<0>(rhs), get<1>(rhs), get<2>(rhs), get<3>(rhs) + f32x4{lhs}};
103 hi_axiom(lhs.holds_invariant() && rhs.holds_invariant());
104 return matrix2{f32x4{rhs}.x000(), f32x4{rhs}._0y00(), f32x4{rhs}._00z0(), f32x4{lhs}.xyz1()};
109 return matrix3{f32x4{rhs}.x000(), f32x4{rhs}._0y00(), f32x4{rhs}._00z0(), f32x4{lhs}.xyz1()};
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()};
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()};
136 return scale2{f32x4{lhs} * f32x4{rhs}};
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
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
228 return vector2{f32x4{lhs} * f32x4{rhs}};
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
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}};
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;
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.
Definition gui_event_variant.hpp:44
The HikoGUI namespace.
Definition array_generic.hpp:21
The HikoGUI API version 1.
Definition array_generic.hpp:22
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
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
A high-level geometric extent.
Definition extent2.hpp:32
A high-level geometric extent.
Definition extent3.hpp:33
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
float height() const noexcept
The height, or length of the up vector.
Definition rectangle.hpp:152
float width() const noexcept
The width, or length of the right vector.
Definition rectangle.hpp:145
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