feat: Fix misleading doc.

This commit is contained in:
Thorben Höhne 2025-05-04 16:30:02 +02:00
parent 77d39b6254
commit 81ef16cc99
Signed by: thoehne
GPG Key ID: 60D202D915B81DEC

View File

@ -9,16 +9,16 @@
#ifndef MATRIX2_H #ifndef MATRIX2_H
# define MATRIX2_H # define MATRIX2_H
namespace Phanes::Core::Math { namespace Phanes::Core::Math
{
// 2x2 Matrix defined in column-major order. // 2x2 Matrix defined in column-major order.
// Accessed by M[Row][Col]. // Accessed by M[Col][Row].
template <RealType T> template <RealType T>
struct TMatrix2 struct TMatrix2
{ {
public: public:
union union
{ {
struct struct
@ -38,7 +38,6 @@ namespace Phanes::Core::Math {
}; };
public: public:
TMatrix2() = default; TMatrix2() = default;
/** /**
@ -59,8 +58,10 @@ namespace Phanes::Core::Math {
TMatrix2(T fields[2][2]) TMatrix2(T fields[2][2])
{ {
this->data[0][0] = fields[0][0]; this->data[1][0] = fields[1][0]; this->data[0][0] = fields[0][0];
this->data[0][1] = fields[0][1]; this->data[1][1] = fields[1][1]; this->data[1][0] = fields[1][0];
this->data[0][1] = fields[0][1];
this->data[1][1] = fields[1][1];
} }
/** /**
@ -76,8 +77,10 @@ namespace Phanes::Core::Math {
TMatrix2(T n00, T n01, T n10, T n11) TMatrix2(T n00, T n01, T n10, T n11)
{ {
this->data[0][0] = n00; this->data[1][0] = n01; this->data[0][0] = n00;
this->data[0][1] = n10; this->data[1][1] = n11; this->data[1][0] = n01;
this->data[0][1] = n10;
this->data[1][1] = n11;
} }
/** /**
@ -94,8 +97,6 @@ namespace Phanes::Core::Math {
} }
public: public:
T& operator()(int n, int m) T& operator()(int n, int m)
{ {
return this->data[m][n]; return this->data[m][n];
@ -131,7 +132,6 @@ namespace Phanes::Core::Math {
throw std::invalid_argument("m is outside valid range."); throw std::invalid_argument("m is outside valid range.");
} }
}; };
// ====================== // // ====================== //
@ -222,58 +222,55 @@ namespace Phanes::Core::Math {
template <RealType T> template <RealType T>
TMatrix2<T> operator+(const TMatrix2<T>& m1, T s) TMatrix2<T> operator+(const TMatrix2<T>& m1, T s)
{ {
return TMatrix2<T>(m1(0, 0) + s, m1(0, 1) + s, return TMatrix2<T>(m1(0, 0) + s, m1(0, 1) + s, m1(1, 0) + s, m1(1, 1) + s);
m1(1, 0) + s, m1(1, 1) + s);
} }
template <RealType T> template <RealType T>
TMatrix2<T> operator+(const TMatrix2<T>& m1, const TMatrix2<T>& m2) TMatrix2<T> operator+(const TMatrix2<T>& m1, const TMatrix2<T>& m2)
{ {
return TMatrix2<T>(m1(0, 0) + m2(0, 0), m1(0, 1) + m2(0, 1), return TMatrix2<T>(
m1(1, 0) + m2(1, 0), m1(1, 1) + m2(1, 1)); m1(0, 0) + m2(0, 0), m1(0, 1) + m2(0, 1), m1(1, 0) + m2(1, 0), m1(1, 1) + m2(1, 1));
} }
template <RealType T> template <RealType T>
TMatrix2<T> operator-(const TMatrix2<T>& m1, T s) TMatrix2<T> operator-(const TMatrix2<T>& m1, T s)
{ {
return TMatrix2<T>(m1(0, 0) - s, m1(0, 1) - s, return TMatrix2<T>(m1(0, 0) - s, m1(0, 1) - s, m1(1, 0) - s, m1(1, 1) - s);
m1(1, 0) - s, m1(1, 1) - s);
} }
template <RealType T> template <RealType T>
TMatrix2<T> operator-(const TMatrix2<T>& m1, const TMatrix2<T>& m2) TMatrix2<T> operator-(const TMatrix2<T>& m1, const TMatrix2<T>& m2)
{ {
return TMatrix2<T>(m1(0, 0) - m2(0, 0), m1(0, 1) - m2(0, 1), return TMatrix2<T>(
m1(1, 0) - m2(1, 0), m1(1, 1) - m2(1, 1)); m1(0, 0) - m2(0, 0), m1(0, 1) - m2(0, 1), m1(1, 0) - m2(1, 0), m1(1, 1) - m2(1, 1));
} }
template <RealType T> template <RealType T>
TMatrix2<T> operator*(const TMatrix2<T>& m1, T s) TMatrix2<T> operator*(const TMatrix2<T>& m1, T s)
{ {
return TMatrix2<T>(m1(0, 0) * s, m1(0, 1) * s, return TMatrix2<T>(m1(0, 0) * s, m1(0, 1) * s, m1(1, 0) * s, m1(1, 1) * s);
m1(1, 0) * s, m1(1, 1) * s);
} }
template <RealType T> template <RealType T>
TMatrix2<T> operator/(const TMatrix2<T>& m1, T s) TMatrix2<T> operator/(const TMatrix2<T>& m1, T s)
{ {
s = (T)1.0 / s; s = (T)1.0 / s;
return TMatrix2<T>(m1(0, 0) * s, m1(0, 1) * s, return TMatrix2<T>(m1(0, 0) * s, m1(0, 1) * s, m1(1, 0) * s, m1(1, 1) * s);
m1(1, 0) * s, m1(1, 1) * s);
} }
template <RealType T> template <RealType T>
TMatrix2<T> operator*(const TMatrix2<T>& m1, const TMatrix2<T>& m2) TMatrix2<T> operator*(const TMatrix2<T>& m1, const TMatrix2<T>& m2)
{ {
return TMatrix2<T>(m1(0, 0) * m2(0, 0) + m1(0, 1) * m2(1, 0), m1(0, 0) * m2(0, 1) + m1(0, 1) * m2(1, 1), return TMatrix2<T>(m1(0, 0) * m2(0, 0) + m1(0, 1) * m2(1, 0),
m1(1, 0) * m2(0, 0) + m1(1, 1) * m2(1, 0), m1(1, 0) * m2(0, 1) + m1(1, 1) * m2(1, 1)); m1(0, 0) * m2(0, 1) + m1(0, 1) * m2(1, 1),
m1(1, 0) * m2(0, 0) + m1(1, 1) * m2(1, 0),
m1(1, 0) * m2(0, 1) + m1(1, 1) * m2(1, 1));
} }
template <RealType T> template <RealType T>
TVector2<T, false> operator*(const TMatrix2<T>& m1, const TVector2<T, false>& v) TVector2<T, false> operator*(const TMatrix2<T>& m1, const TVector2<T, false>& v)
{ {
return TVector2<T, false>(m1(0, 0) * v.x + m1(0, 1) * v.y, return TVector2<T, false>(m1(0, 0) * v.x + m1(0, 1) * v.y, m1(1, 0) * v.x + m1(1, 1) * v.y);
m1(1, 0) * v.x + m1(1, 1) * v.y);
} }
template <RealType T> template <RealType T>
@ -288,7 +285,6 @@ namespace Phanes::Core::Math {
return m1[0] != m2[0] || m1[1] != m2[1]; return m1[0] != m2[0] || m1[1] != m2[1];
} }
// ============================== // // ============================== //
// Matrix function definition // // Matrix function definition //
// ============================== // // ============================== //
@ -331,15 +327,14 @@ namespace Phanes::Core::Math {
{ {
float _1_det = 1.0f / Determinant(m1); float _1_det = 1.0f / Determinant(m1);
return TMatrix2<T>( m1(1, 1) * _1_det, -m1(0, 1) * _1_det, return TMatrix2<T>(
-m1(1, 0) * _1_det, m1(0, 0) * _1_det); m1(1, 1) * _1_det, -m1(0, 1) * _1_det, -m1(1, 0) * _1_det, m1(0, 0) * _1_det);
} }
template <RealType T> template <RealType T>
TMatrix2<T> Transpose(const TMatrix2<T>& m1) TMatrix2<T> Transpose(const TMatrix2<T>& m1)
{ {
return TMatrix2<T>(m1(0, 0), m1(1, 0), return TMatrix2<T>(m1(0, 0), m1(1, 0), m1(0, 1), m1(1, 1));
m1(0, 1), m1(1, 1));
} }
template <RealType T> template <RealType T>
@ -349,10 +344,8 @@ namespace Phanes::Core::Math {
abs(m1(1, 0)) < P_FLT_INAC && abs(m1(1, 1) - (T)1.0) < P_FLT_INAC); abs(m1(1, 0)) < P_FLT_INAC && abs(m1(1, 1) - (T)1.0) < P_FLT_INAC);
} }
} // Phanes::Core::Math } // namespace Phanes::Core::Math
#endif // !MATRIX2_H #endif // !MATRIX2_H
#include "Core/Math/SIMD/SIMDIntrinsics.h" #include "Core/Math/SIMD/SIMDIntrinsics.h"