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())
109 _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)
154 _col0(c0r0, c0r1, c0r2, c0r3), _col1(c1r0, c1r1, c1r2, c1r3), _col2(c2r0, c2r1, c2r2, c2r3), _col3(c3r0, c3r1, c3r2, c3r3)
185 return {_col0, _col1, _col2, _col3};
197 [[nodiscard]]
constexpr static matrix
206 [[nodiscard]]
friend constexpr f32x4
const&
get(
matrix const& rhs)
noexcept
208 if constexpr (I == 0) {
210 }
else if constexpr (I == 1) {
212 }
else if constexpr (I == 2) {
214 }
else if constexpr (I == 3) {
227 [[nodiscard]]
friend constexpr f32x4&
get(
matrix& rhs)
noexcept
229 if constexpr (I == 0) {
231 }
else if constexpr (I == 1) {
233 }
else if constexpr (I == 2) {
235 }
else if constexpr (I == 3) {
242 [[nodiscard]]
constexpr bool holds_invariant() const noexcept
252 [[nodiscard]]
constexpr f32x4
operator*(f32x4
const& rhs)
const noexcept
254 return {_col0 * rhs.xxxx() + _col1 * rhs.yyyy() + _col2 * rhs.zzzz() + _col3 * rhs.wwww()};
262 [[nodiscard]]
constexpr float operator*(
float const& rhs)
const noexcept
265 auto abs_scale = hypot<D>(_col0 * f32x4::broadcast(rhs));
278 return {*
this * get<0>(rhs), *
this * get<1>(rhs), *
this * get<2>(rhs), *
this * get<3>(rhs)};
289 [[nodiscard]]
constexpr auto operator*(vector<float, E>
const& rhs)
const noexcept
292 return vector<float,
std::max(D, E)>{
293 _col0 *
static_cast<f32x4
>(rhs).xxxx() + _col1 *
static_cast<f32x4
>(rhs).yyyy() +
294 _col2 *
static_cast<f32x4
>(rhs).zzzz()};
309 _col0 *
static_cast<f32x4
>(rhs).xxxx() + _col1 *
static_cast<f32x4
>(rhs).yyyy() +
310 _col2 *
static_cast<f32x4
>(rhs).zzzz()};
319 [[nodiscard]]
constexpr auto operator*(point<float, E>
const& rhs)
const noexcept
322 return point<float,
std::max(D, E)>{
323 _col0 *
static_cast<f32x4
>(rhs).xxxx() + _col1 *
static_cast<f32x4
>(rhs).yyyy() +
324 _col2 *
static_cast<f32x4
>(rhs).zzzz() + _col3 *
static_cast<f32x4
>(rhs).wwww()};
349 return rectangle{*
this * rhs.origin, *
this * rhs.right, *
this * rhs.up};
357 [[nodiscard]]
constexpr quad
operator*(quad
const& rhs)
const noexcept
359 return quad{*
this * rhs.p0, *
this * rhs.p1, *
this * rhs.p2, *
this * rhs.p3};
369 return circle{*
this * midpoint(rhs), *
this * rhs.radius()};
379 return line_segment{*
this * rhs.origin(), *
this * rhs.direction()};
386 return matrix{*
this * get<0>(rhs), *
this * get<1>(rhs), *
this * get<2>(rhs), *
this * get<3>(rhs)};
393 auto tmp =
transpose(rhs._col0, rhs._col1, rhs._col2, rhs._col3);
394 return {std::get<0>(tmp), std::get<1>(tmp), std::get<2>(tmp), std::get<3>(tmp)};
431 template<
char DstX,
char DstY,
char DstZ,
char DstW = 'w'>
435 return matrix{reflect_column<DstX>(), reflect_column<DstY>(), reflect_column<DstZ>(), reflect_column<DstW>()} * rhs;
446 return _col0 == rhs._col0 && _col1 == rhs._col1 && _col2 == rhs._col2 && _col3 == rhs._col3;
458 hilet s0c0 = _col0 * _col1.yxwz();
464 hilet s1c1 = _col0 * _col2.yxwz();
465 hilet s0c0s1c1 = hsub(s0c0, s1c1);
471 hilet s2c2 = _col0 * _col3.yxwz();
477 hilet s3c3 = _col1 * _col2.yxwz();
478 hilet s2c2s3c3 = hsub(s2c2, s3c3);
484 hilet s4c4 = _col1 * _col3.yxwz();
490 hilet s5c5 = _col2 * _col3.yxwz();
491 hilet s4c4s5c5 = hsub(s4c4, s5c5);
499 hilet s0123 = s0c0s1c1.xz00() + s2c2s3c3._00xz();
500 hilet s45__ = s4c4s5c5.xz00();
502 hilet c5432 = s4c4s5c5.wy00() + s2c2s3c3._00wy();
503 hilet c10__ = s0c0s1c1.wy00();
505 hilet det_prod_half0 = neg<0b0010>(s0123 * c5432);
506 hilet det_prod_half1 = neg<0b0001>(s45__ * c10__);
508 hilet det_sum0 = hadd(det_prod_half0, det_prod_half1);
509 hilet det_sum1 = hadd(det_sum0, det_sum0);
510 hilet det = hadd(det_sum1, det_sum1).xxxx();
512 if (det.x() == 0.0f) {
516 hilet invdet = rcp(det);
525 auto tmp_c5543 = neg<0b1010>(c5432.xxyz());
526 auto tmp_c4221 = neg<0b0101>(c5432.yww0() + c10__._000x());
527 auto tmp_c3100 = neg<0b1010>(c5432.z000() + c10__._0xyy());
528 hilet inv_col0 = ((t._col1.yxxx() * tmp_c5543) + (t._col1.zzyy() * tmp_c4221) + (t._col1.wwwz() * tmp_c3100)) * invdet;
534 tmp_c5543 = -tmp_c5543;
535 tmp_c4221 = -tmp_c4221;
536 tmp_c3100 = -tmp_c3100;
537 hilet inv_col1 = ((t._col0.yxxx() * tmp_c5543) + (t._col0.zzyy() * tmp_c4221) + (t._col0.wwwz() * tmp_c3100)) * invdet;
543 auto tmp_s5543 = neg<0b1010>(s45__.yyx0() + s0123._000w());
544 auto tmp_s4221 = neg<0b0101>(s45__.x000() + s0123._0zzy());
545 auto tmp_s3100 = neg<0b1010>(s0123.wyxx());
546 hilet inv_col2 = ((t._col3.yxxx() * tmp_s5543) + (t._col3.zzyy() * tmp_s4221) + (t._col3.wwwz() * tmp_s3100)) * invdet;
552 tmp_s5543 = -tmp_s5543;
553 tmp_s4221 = -tmp_s4221;
554 tmp_s3100 = -tmp_s3100;
555 hilet inv_col3 = ((t._col2.yxxx() * tmp_s5543) + (t._col2.zzyy() * tmp_s4221) + (t._col2.wwwz() * tmp_s3100)) * invdet;
557 return {inv_col0, inv_col1, inv_col2, inv_col3};
567 [[nodiscard]]
static constexpr f32x4 reflect_column() noexcept
569 if constexpr (Axis ==
'x') {
570 return f32x4{1.0f, 0.0f, 0.0f, 0.0f};
571 }
else if constexpr (Axis ==
'X') {
572 return f32x4{-1.0f, 0.0f, 0.0f, 0.0f};
573 }
else if constexpr (Axis ==
'y') {
574 return f32x4{0.0f, 1.0f, 0.0f, 0.0f};
575 }
else if constexpr (Axis ==
'Y') {
576 return f32x4{0.0f, -1.0f, 0.0f, 0.0f};
577 }
else if constexpr (Axis ==
'z') {
578 return f32x4{0.0f, 0.0f, 1.0f, 0.0f};
579 }
else if constexpr (Axis ==
'Z') {
580 return f32x4{0.0f, 0.0f, -1.0f, 0.0f};
581 }
else if constexpr (Axis ==
'w') {
582 return f32x4{0.0f, 0.0f, 0.0f, 1.0f};
583 }
else if constexpr (Axis ==
'W') {
584 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:308
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
#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:595
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:26
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:18
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:206
friend constexpr matrix reflect(matrix const &rhs) noexcept
Reflect axis of a matrix.
Definition matrix.hpp:432
constexpr bool operator==(matrix< E > const &rhs) const noexcept
Compare two matrices potentially of different dimensions.
Definition matrix.hpp:444
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:97
constexpr float operator*(float const &rhs) const noexcept
Transform a float by the scaling factor of the matrix.
Definition matrix.hpp:262
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:289
constexpr matrix operator~() const
Invert matrix.
Definition matrix.hpp:451
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:211
constexpr auto operator*(matrix const &rhs) const noexcept
Matrix/Matrix multiplication.
Definition matrix.hpp:384
constexpr rectangle operator*(rectangle const &rhs) const noexcept
Transform a rectangle by the matrix.
Definition matrix.hpp:347
constexpr rectangle operator*(aarectangle const &rhs) const noexcept
Transform an axis-aligned rectangle by the matrix.
Definition matrix.hpp:336
friend constexpr f32x4 & get(matrix &rhs) noexcept
Get a column.
Definition matrix.hpp:227
constexpr corner_radii operator*(corner_radii const &rhs) const noexcept
Transform a float by the scaling factor of the matrix.
Definition matrix.hpp:276
constexpr matrix(matrix< E > const &other) noexcept
Copy-construct a matrix from a smaller matrix.
Definition matrix.hpp:162
constexpr circle operator*(circle const &rhs) const noexcept
Transform a circle by the matrix.
Definition matrix.hpp:367
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:135
constexpr auto operator*(point< float, E > const &rhs) const noexcept
Transform a point by the matrix.
Definition matrix.hpp:319
constexpr auto operator*(extent< float, E > const &rhs) const noexcept
Transform a extent by the matrix.
Definition matrix.hpp:305
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:252
constexpr line_segment operator*(line_segment const &rhs) const noexcept
Transform a line-segment by the matrix.
Definition matrix.hpp:377
friend constexpr matrix transpose(matrix const &rhs) noexcept
Matrix transpose.
Definition matrix.hpp:391
constexpr quad operator*(quad const &rhs) const noexcept
Transform a quad by the matrix.
Definition matrix.hpp:357
constexpr matrix(vector3 col0, vector3 col1, vector3 col2, vector3 col3=vector3{}) noexcept
Construct a matrix from four vectors.
Definition matrix.hpp:72