14#include "rectangle.hpp"
35 static_assert(D == 2 || D == 3,
"Only 2D or 3D rotation-matrices are supported");
39 constexpr matrix& operator=(
matrix const&)
noexcept =
default;
40 constexpr matrix& operator=(
matrix&&)
noexcept =
default;
46 hilet a = f32x4::broadcast(1.0f);
60 constexpr matrix(f32x4 col0, f32x4 col1, f32x4 col2, f32x4 col3 = f32x4{0.0f, 0.0f, 0.0f, 1.0f})
noexcept :
61 _col0(col0), _col1(col1), _col2(col2), _col3(col3)
72 constexpr matrix(vector3 col0, vector3 col1, vector3 col2, vector3 col3 = vector3{})
noexcept
75 _col0(static_cast<f32x4>(col0)),
76 _col1(static_cast<f32x4>(col1)),
77 _col2(static_cast<f32x4>(col2)),
78 _col3(static_cast<f32x4>(col3).xyz1())
87 constexpr matrix(vector2 col0, vector2 col1)
noexcept
90 _col0(static_cast<f32x4>(col0)),
91 _col1(static_cast<f32x4>(col1)),
92 _col2(f32x4{0.0f, 0.0f, 1.0f, 0.0f}),
93 _col3(f32x4{0.0f, 0.0f, 0.0f, 1.0f})
124 _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)
169 _col0(c0r0, c0r1, c0r2, c0r3), _col1(c1r0, c1r1, c1r2, c1r3), _col2(c2r0, c2r1, c2r2, c2r3), _col3(c3r0, c3r1, c3r2, c3r3)
200 return {_col0, _col1, _col2, _col3};
212 [[nodiscard]]
constexpr static matrix
221 [[nodiscard]]
friend constexpr f32x4
const&
get(
matrix const& rhs)
noexcept
223 if constexpr (I == 0) {
225 }
else if constexpr (I == 1) {
227 }
else if constexpr (I == 2) {
229 }
else if constexpr (I == 3) {
242 [[nodiscard]]
friend constexpr f32x4&
get(
matrix& rhs)
noexcept
244 if constexpr (I == 0) {
246 }
else if constexpr (I == 1) {
248 }
else if constexpr (I == 2) {
250 }
else if constexpr (I == 3) {
257 [[nodiscard]]
constexpr bool holds_invariant() const noexcept
267 [[nodiscard]]
constexpr f32x4
operator*(f32x4
const& rhs)
const noexcept
269 return {_col0 * rhs.xxxx() + _col1 * rhs.yyyy() + _col2 * rhs.zzzz() + _col3 * rhs.wwww()};
277 [[nodiscard]]
constexpr float operator*(
float const& rhs)
const noexcept
280 auto abs_scale = hypot<D>(_col0 * f32x4::broadcast(rhs));
293 return {*
this * get<0>(rhs), *
this * get<1>(rhs), *
this * get<2>(rhs), *
this * get<3>(rhs)};
304 [[nodiscard]]
constexpr auto operator*(vector<float, E>
const& rhs)
const noexcept
307 return vector<float,
std::max(D, E)>{
308 _col0 *
static_cast<f32x4
>(rhs).xxxx() + _col1 *
static_cast<f32x4
>(rhs).yyyy() +
309 _col2 *
static_cast<f32x4
>(rhs).zzzz()};
324 _col0 *
static_cast<f32x4
>(rhs).xxxx() + _col1 *
static_cast<f32x4
>(rhs).yyyy() +
325 _col2 *
static_cast<f32x4
>(rhs).zzzz()};
334 [[nodiscard]]
constexpr auto operator*(point<float, E>
const& rhs)
const noexcept
337 return point<float,
std::max(D, E)>{
338 _col0 *
static_cast<f32x4
>(rhs).xxxx() + _col1 *
static_cast<f32x4
>(rhs).yyyy() +
339 _col2 *
static_cast<f32x4
>(rhs).zzzz() + _col3 *
static_cast<f32x4
>(rhs).wwww()};
364 return rectangle{*
this * rhs.origin, *
this * rhs.right, *
this * rhs.up};
372 [[nodiscard]]
constexpr quad
operator*(quad
const& rhs)
const noexcept
374 return quad{*
this * rhs.p0, *
this * rhs.p1, *
this * rhs.p2, *
this * rhs.p3};
384 return circle{*
this * midpoint(rhs), *
this * rhs.radius()};
394 return line_segment{*
this * rhs.origin(), *
this * rhs.direction()};
401 return matrix{*
this * get<0>(rhs), *
this * get<1>(rhs), *
this * get<2>(rhs), *
this * get<3>(rhs)};
408 auto tmp =
transpose(rhs._col0, rhs._col1, rhs._col2, rhs._col3);
409 return {std::get<0>(tmp), std::get<1>(tmp), std::get<2>(tmp), std::get<3>(tmp)};
446 template<
char DstX,
char DstY,
char DstZ,
char DstW = 'w'>
450 return matrix{reflect_column<DstX>(), reflect_column<DstY>(), reflect_column<DstZ>(), reflect_column<DstW>()} * rhs;
461 return _col0 == rhs._col0 && _col1 == rhs._col1 && _col2 == rhs._col2 && _col3 == rhs._col3;
473 hilet s0c0 = _col0 * _col1.yxwz();
479 hilet s1c1 = _col0 * _col2.yxwz();
480 hilet s0c0s1c1 = hsub(s0c0, s1c1);
486 hilet s2c2 = _col0 * _col3.yxwz();
492 hilet s3c3 = _col1 * _col2.yxwz();
493 hilet s2c2s3c3 = hsub(s2c2, s3c3);
499 hilet s4c4 = _col1 * _col3.yxwz();
505 hilet s5c5 = _col2 * _col3.yxwz();
506 hilet s4c4s5c5 = hsub(s4c4, s5c5);
514 hilet s0123 = s0c0s1c1.xz00() + s2c2s3c3._00xz();
515 hilet s45__ = s4c4s5c5.xz00();
517 hilet c5432 = s4c4s5c5.wy00() + s2c2s3c3._00wy();
518 hilet c10__ = s0c0s1c1.wy00();
520 hilet det_prod_half0 = neg<0b0010>(s0123 * c5432);
521 hilet det_prod_half1 = neg<0b0001>(s45__ * c10__);
523 hilet det_sum0 = hadd(det_prod_half0, det_prod_half1);
524 hilet det_sum1 = hadd(det_sum0, det_sum0);
525 hilet det = hadd(det_sum1, det_sum1).xxxx();
527 if (det.x() == 0.0f) {
531 hilet invdet = rcp(det);
540 auto tmp_c5543 = neg<0b1010>(c5432.xxyz());
541 auto tmp_c4221 = neg<0b0101>(c5432.yww0() + c10__._000x());
542 auto tmp_c3100 = neg<0b1010>(c5432.z000() + c10__._0xyy());
543 hilet inv_col0 = ((t._col1.yxxx() * tmp_c5543) + (t._col1.zzyy() * tmp_c4221) + (t._col1.wwwz() * tmp_c3100)) * invdet;
549 tmp_c5543 = -tmp_c5543;
550 tmp_c4221 = -tmp_c4221;
551 tmp_c3100 = -tmp_c3100;
552 hilet inv_col1 = ((t._col0.yxxx() * tmp_c5543) + (t._col0.zzyy() * tmp_c4221) + (t._col0.wwwz() * tmp_c3100)) * invdet;
558 auto tmp_s5543 = neg<0b1010>(s45__.yyx0() + s0123._000w());
559 auto tmp_s4221 = neg<0b0101>(s45__.x000() + s0123._0zzy());
560 auto tmp_s3100 = neg<0b1010>(s0123.wyxx());
561 hilet inv_col2 = ((t._col3.yxxx() * tmp_s5543) + (t._col3.zzyy() * tmp_s4221) + (t._col3.wwwz() * tmp_s3100)) * invdet;
567 tmp_s5543 = -tmp_s5543;
568 tmp_s4221 = -tmp_s4221;
569 tmp_s3100 = -tmp_s3100;
570 hilet inv_col3 = ((t._col2.yxxx() * tmp_s5543) + (t._col2.zzyy() * tmp_s4221) + (t._col2.wwwz() * tmp_s3100)) * invdet;
572 return {inv_col0, inv_col1, inv_col2, inv_col3};
582 [[nodiscard]]
static constexpr f32x4 reflect_column() noexcept
584 if constexpr (Axis ==
'x') {
585 return f32x4{1.0f, 0.0f, 0.0f, 0.0f};
586 }
else if constexpr (Axis ==
'X') {
587 return f32x4{-1.0f, 0.0f, 0.0f, 0.0f};
588 }
else if constexpr (Axis ==
'y') {
589 return f32x4{0.0f, 1.0f, 0.0f, 0.0f};
590 }
else if constexpr (Axis ==
'Y') {
591 return f32x4{0.0f, -1.0f, 0.0f, 0.0f};
592 }
else if constexpr (Axis ==
'z') {
593 return f32x4{0.0f, 0.0f, 1.0f, 0.0f};
594 }
else if constexpr (Axis ==
'Z') {
595 return f32x4{0.0f, 0.0f, -1.0f, 0.0f};
596 }
else if constexpr (Axis ==
'w') {
597 return f32x4{0.0f, 0.0f, 0.0f, 1.0f};
598 }
else if constexpr (Axis ==
'W') {
599 return f32x4{0.0f, 0.0f, 0.0f, -1.0f};
Defined the geo::extent, extent2 and extent3 types.
Defined the corner_radii type.
#define hi_static_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:323
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
@ other
The gui_event does not have associated data.
@ rectangle
The gui_event has rectangle data.
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
geo::matrix< 2 > matrix2
A 2D homogenious transformation matrix.
Definition matrix.hpp:610
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:27
A type defining a 2D circle.
Definition circle.hpp:18
The 4 radii of the corners of a quad or rectangle.
Definition corner_radii.hpp:19
A high-level geometric extent.
Definition extent.hpp:30
Line segment.
Definition line_segment.hpp:19
A 2D or 3D homogenius matrix for transforming homogenious vectors and points.
Definition matrix.hpp:33
friend constexpr f32x4 const & get(matrix const &rhs) noexcept
Get a column.
Definition matrix.hpp:221
friend constexpr matrix reflect(matrix const &rhs) noexcept
Reflect axis of a matrix.
Definition matrix.hpp:447
constexpr bool operator==(matrix< E > const &rhs) const noexcept
Compare two matrices potentially of different dimensions.
Definition matrix.hpp:459
constexpr matrix(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 matrix.hpp:112
constexpr float operator*(float const &rhs) const noexcept
Transform a float by the scaling factor of the matrix.
Definition matrix.hpp:277
constexpr matrix(vector2 col0, vector2 col1) noexcept
Construct a matrix from four vectors.
Definition matrix.hpp:87
constexpr matrix(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 matrix.hpp:60
constexpr auto operator*(vector< float, E > const &rhs) const noexcept
Transform a vector by the matrix.
Definition matrix.hpp:304
constexpr matrix operator~() const
Invert matrix.
Definition matrix.hpp:466
static constexpr matrix 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 scale.hpp:240
constexpr auto operator*(matrix const &rhs) const noexcept
Matrix/Matrix multiplication.
Definition matrix.hpp:399
constexpr rectangle operator*(rectangle const &rhs) const noexcept
Transform a rectangle by the matrix.
Definition matrix.hpp:362
constexpr rectangle operator*(aarectangle const &rhs) const noexcept
Transform an axis-aligned rectangle by the matrix.
Definition matrix.hpp:351
friend constexpr f32x4 & get(matrix &rhs) noexcept
Get a column.
Definition matrix.hpp:242
constexpr matrix(matrix< E > const &other) noexcept
Copy-construct a matrix from a smaller matrix.
Definition matrix.hpp:177
constexpr corner_radii< float > operator*(corner_radii< float > const &rhs) const noexcept
Transform a float by the scaling factor of the matrix.
Definition matrix.hpp:291
constexpr circle operator*(circle const &rhs) const noexcept
Transform a circle by the matrix.
Definition matrix.hpp:382
constexpr matrix(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 matrix.hpp:150
constexpr auto operator*(point< float, E > const &rhs) const noexcept
Transform a point by the matrix.
Definition matrix.hpp:334
constexpr auto operator*(extent< float, E > const &rhs) const noexcept
Transform a extent by the matrix.
Definition matrix.hpp:320
constexpr matrix() noexcept
Constructs an identity matrix.
Definition matrix.hpp:44
constexpr f32x4 operator*(f32x4 const &rhs) const noexcept
Transform a f32x4 numeric array by the matrix.
Definition matrix.hpp:267
constexpr line_segment operator*(line_segment const &rhs) const noexcept
Transform a line-segment by the matrix.
Definition matrix.hpp:392
friend constexpr matrix transpose(matrix const &rhs) noexcept
Matrix transpose.
Definition matrix.hpp:406
constexpr quad operator*(quad const &rhs) const noexcept
Transform a quad by the matrix.
Definition matrix.hpp:372
constexpr matrix(vector3 col0, vector3 col1, vector3 col2, vector3 col3=vector3{}) noexcept
Construct a matrix from four vectors.
Definition matrix.hpp:72