11#include "translate2.hpp"
15#include "../macros.hpp"
21hi_export_module(hikogui.geometry : matrix2);
23hi_export
namespace hi {
inline namespace v1 {
29[[nodiscard]]
constexpr matrix2
operator*(matrix2
const& lhs, matrix2
const& rhs)
noexcept;
30[[nodiscard]]
constexpr aarectangle
operator*(scale2
const& lhs, aarectangle
const& rhs)
noexcept;
31[[nodiscard]]
constexpr matrix2
operator*(translate2
const& lhs, scale2
const& rhs)
noexcept;
50 auto const a = f32x4::broadcast(1.0f);
67 hi_axiom(holds_invariant());
83 hi_axiom(holds_invariant());
94 _col2(
f32x4{0.0f, 0.0f, 1.0f, 0.0f}),
95 _col3(
f32x4{0.0f, 0.0f, 0.0f, 1.0f})
97 hi_axiom(holds_invariant());
125 _col0(
c0r0,
c0r1,
c0r2, 0.0f), _col1(
c1r0,
c1r1,
c1r2, 0.0f), _col2(
c2r0,
c2r1,
c2r2, 0.0f), _col3(0.0f, 0.0f, 0.0f, 1.0f)
127 hi_axiom(holds_invariant());
169 _col0(
c0r0,
c0r1,
c0r2,
c0r3), _col1(
c1r0,
c1r1,
c1r2,
c1r3), _col2(
c2r0,
c2r1,
c2r2,
c2r3), _col3(
c3r0,
c3r1,
c3r2,
c3r3)
171 hi_axiom(holds_invariant());
176 auto const ones = f32x4::broadcast(1.0f);
178 _col1 =
ones._0y00();
179 _col2 =
ones._00z0();
185 _col0 = f32x4{rhs}.x000();
186 _col1 = f32x4{rhs}._0y00();
187 _col2 = f32x4{rhs}._00z0();
188 _col3 = f32x4{rhs}._000w();
211 auto twos =
f32x4{-2.0f, 2.0f, 2.0f, 0.0f};
212 auto one =
f32x4{1.0f, 0.0f, 0.0f, 0.0f};
227 hi_axiom(holds_invariant());
228 return {_col0, _col1, _col2, _col3};
257 if constexpr (I == 0) {
259 }
else if constexpr (I == 1) {
261 }
else if constexpr (I == 2) {
263 }
else if constexpr (I == 3) {
266 hi_static_no_default();
278 if constexpr (I == 0) {
280 }
else if constexpr (I == 1) {
282 }
else if constexpr (I == 2) {
284 }
else if constexpr (I == 3) {
287 hi_static_no_default();
293 return _col0.z() == 0.0f
and _col0.w() == 0.0f
and _col1.z() == 0.0f
and _col1.w() == 0.0f
and _col2.x() == 0.0f
and
294 _col2.y() == 0.0f
and _col2.z() == 1.0f
and _col2.w() == 0.0f
and _col3.z() == 0.0f
and _col3.w() == 1.0f;
304 return {_col0 * rhs.xxxx() + _col1 * rhs.yyyy() + _col2 * rhs.zzzz() + _col3 * rhs.wwww()};
311 auto tmp =
transpose(rhs._col0, rhs._col1, rhs._col2, rhs._col3);
348 template<
char DstX,
char DstY,
char DstZ,
char DstW = 'w'>
361 return equal(lhs._col0, rhs._col0)
and equal(lhs._col1, rhs._col1)
and equal(lhs._col3, rhs._col3);
373 auto const s0c0 = _col0 * _col1.yxwz();
379 auto const s1c1 = _col0 * _col2.yxwz();
386 auto const s2c2 = _col0 * _col3.yxwz();
392 auto const s3c3 = _col1 * _col2.yxwz();
399 auto const s4c4 = _col1 * _col3.yxwz();
405 auto const s5c5 = _col2 * _col3.yxwz();
427 if (det.x() == 0.0f) {
431 auto const invdet = rcp(det);
484 if constexpr (
Axis ==
'x') {
485 return f32x4{1.0f, 0.0f, 0.0f, 0.0f};
486 }
else if constexpr (
Axis ==
'X') {
487 return f32x4{-1.0f, 0.0f, 0.0f, 0.0f};
488 }
else if constexpr (
Axis ==
'y') {
489 return f32x4{0.0f, 1.0f, 0.0f, 0.0f};
490 }
else if constexpr (
Axis ==
'Y') {
491 return f32x4{0.0f, -1.0f, 0.0f, 0.0f};
492 }
else if constexpr (
Axis ==
'z') {
493 return f32x4{0.0f, 0.0f, 1.0f, 0.0f};
494 }
else if constexpr (
Axis ==
'Z') {
495 return f32x4{0.0f, 0.0f, -1.0f, 0.0f};
496 }
else if constexpr (
Axis ==
'w') {
497 return f32x4{0.0f, 0.0f, 0.0f, 1.0f};
498 }
else if constexpr (
Axis ==
'W') {
499 return f32x4{0.0f, 0.0f, 0.0f, -1.0f};
501 hi_static_no_default();
The HikoGUI namespace.
Definition array_generic.hpp:20
@ one
The number was one, and this means something in the current language.
constexpr matrix2 operator*(matrix2 const &lhs, matrix2 const &rhs) noexcept
Matrix/Matrix multiplication.
Definition transform.hpp:69
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
Horizontal/Vertical alignment combination.
Definition alignment.hpp:244
A 2D or 3D homogenius matrix for transforming homogenious vectors and points.
Definition matrix2.hpp:39
constexpr matrix2(rotate2 const &rhs) noexcept
Convert quaternion to matrix.
Definition matrix2.hpp:194
constexpr matrix2(float c0r0, float c1r0, float c2r0, float c0r1, float c1r1, float c2r1, float c0r2, float c1r2, float c2r2) noexcept
Construct a 3x3 matrix from scalar values.
Definition matrix2.hpp:115
constexpr friend bool operator==(matrix2 const &lhs, matrix2 const &rhs) noexcept
Compare two matrices potentially of different dimensions.
Definition matrix2.hpp:359
constexpr matrix2(vector3 col0, vector3 col1, vector3 col2, vector3 col3=vector3{}) noexcept
Construct a matrix from four vectors.
Definition matrix2.hpp:77
friend constexpr f32x4 & get(matrix2 &rhs) noexcept
Get a column.
Definition matrix2.hpp:276
constexpr matrix2(float c0r0, float c1r0, float c2r0, float c3r0, float c0r1, float c1r1, float c2r1, float c3r1, float c0r2, float c1r2, float c2r2, float c3r2, float c0r3, float c1r3, float c2r3, float c3r3) noexcept
Construct a 4x4 matrix from scalar values.
Definition matrix2.hpp:152
constexpr f32x4 operator*(f32x4 const &rhs) const noexcept
Transform a f32x4 numeric array by the matrix.
Definition matrix2.hpp:302
static constexpr matrix2 uniform(aarectangle src_rectangle, aarectangle dst_rectangle, alignment alignment) noexcept
Create a transformation matrix to translate and uniformly-scale a src_rectangle to a dst_rectangle.
Definition matrix2.hpp:241
friend constexpr matrix2 transpose(matrix2 const &rhs) noexcept
Matrix transpose.
Definition matrix2.hpp:309
constexpr matrix2 operator~() const
Invert matrix.
Definition matrix2.hpp:366
constexpr matrix2(f32x4 col0, f32x4 col1, f32x4 col2, f32x4 col3=f32x4{0.0f, 0.0f, 0.0f, 1.0f}) noexcept
Construct a matrix from four columns.
Definition matrix2.hpp:64
constexpr matrix2(vector2 col0, vector2 col1) noexcept
Construct a matrix from two vectors.
Definition matrix2.hpp:91
constexpr matrix2() noexcept
Constructs an identity matrix.
Definition matrix2.hpp:48
friend constexpr matrix2 reflect(matrix2 const &rhs) noexcept
Reflect axis of a matrix.
Definition matrix2.hpp:349
friend constexpr f32x4 const & get(matrix2 const &rhs) noexcept
Get a column.
Definition matrix2.hpp:255
Definition rotate2.hpp:17
static constexpr scale2 uniform(extent2 src_extent, extent2 dst_extent) noexcept
Get a uniform-scale-transform to scale an extent to another extent.
Definition scale2.hpp:51
Definition translate2.hpp:18
static constexpr translate2 align(aarectangle src_rectangle, aarectangle dst_rectangle, alignment alignment) noexcept
Align a rectangle within another rectangle.
Definition translate2.hpp:84
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