34 constexpr T
trace() const noexcept {
return xx +
yy; }
38 constexpr T
det() const noexcept;
49 if constexpr ( std::is_integral_v<T> )
50 {
xx /= b;
xy /= b;
yy /= b;
return *
this; }
52 return *
this *= ( 1 / b );
81 a.xx * b.x + a.xy * b.y,
82 a.xy * b.x + a.yy * b.y
101 const auto ka = k * a;
115 {
return !( a == b ); }
135 { b /= a;
return b; }
160 const auto tr =
trace();
161 const auto q = tr / 2;
162 const auto p = std::sqrt( std::max( T(0),
sqr( tr ) - 4 *
det() ) ) / 2;
164 if ( p <= std::abs( q ) * std::numeric_limits<T>::epsilon() )
188 const T lsq0 = row0.lengthSq();
189 const T lsq1 = row1.lengthSq();
190 return lsq0 >= lsq1 ? row0.perpendicular() : row1.perpendicular();
196 const auto tr =
trace();
197 const auto q = tr / 2;
198 const auto p = std::sqrt( std::max( T(0),
sqr( tr ) - 4 *
det() ) ) / 2;
199 if ( p <= std::abs( q ) * std::numeric_limits<T>::epsilon() )
215 const auto d =
det();
216 if ( d > 0 && d > std::max( tol, T( 1e-4 ) ) *
sqr(
trace() ) )
228 const auto eigenvalues =
eigens( &eigenvectors );
229 const auto threshold = std::max( std::abs( eigenvalues[0] ), std::abs( eigenvalues[1] ) ) * tol;
231 for (
int i = 0; i < 2; ++i )
233 if ( std::abs( eigenvalues[i] ) <= threshold )
235 res +=
outerSquare( 1 / eigenvalues[i], eigenvectors[i] );
240 *space = eigenvectors[i];
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:33
BitSet operator-(const BitSet &a, const BitSet &b)
Definition MRBitSet.h:492
SymMatrix2 & operator-=(const SymMatrix2< T > &b)
Definition MRSymMatrix2.h:45
bool operator==(const Allocator< T > &, const Allocator< U > &) noexcept
Definition MRAllocator.h:95
constexpr SymMatrix2() noexcept=default
constexpr SymMatrix2< T > inverse() const noexcept
computes inverse matrix
Definition MRSymMatrix2.h:40
Vector2
Definition MRMeshFwd.h:189
T ValueType
Definition MRSymMatrix2.h:18
constexpr T trace() const noexcept
computes trace of the matrix
Definition MRSymMatrix2.h:34
T xy
Definition MRSymMatrix2.h:21
constexpr auto sqr(T x) noexcept -> decltype(x *x)
squared value; the result type is the type of x*x, which is int for small integer types (char,...
Definition MRMeshFwd.h:799
constexpr SymMatrix2 & operator/=(T b)
Definition MRSymMatrix2.h:47
static constexpr SymMatrix2 diagonal(T diagVal) noexcept
Definition MRSymMatrix2.h:31
Vector2< T > eigenvector(T eigenvalue) const
computes not-unit eigenvector corresponding to a not-repeating eigenvalue
T yy
Definition MRSymMatrix2.h:21
static constexpr SymMatrix2 identity() noexcept
Definition MRSymMatrix2.h:30
constexpr SymMatrix2< T > inverse(T det) const noexcept
computes inverse matrix given determinant of this
bool operator!=(const Color &a, const Color &b)
Definition MRColor.h:107
Vector2< T > eigens(Matrix2< T > *eigenvectors=nullptr) const
Color operator/(const Color &b, float a)
Definition MRColor.h:132
SymMatrix2< T > outerSquare(T k, const Vector2< T > &a)
x = k * a * a^T
Definition MRSymMatrix2.h:99
SymMatrix2< T > outerSquare(const Vector2< T > &a)
x = a * a^T
Definition MRSymMatrix2.h:88
Vector2< T > operator*(const SymMatrix2< T > &a, const Vector2< T > &b)
x = a * b
Definition MRSymMatrix2.h:77
constexpr T det() const noexcept
computes determinant of the matrix
SymMatrix2 & operator+=(const SymMatrix2< T > &b)
Definition MRSymMatrix2.h:44
Matrix2
Definition MRMeshFwd.h:216
constexpr SymMatrix2 & operator*=(T b)
Definition MRSymMatrix2.h:46
constexpr T normSq() const noexcept
computes the squared norm of the matrix, which is equal to the sum of 4 squared elements
Definition MRSymMatrix2.h:36
SymMatrix2< T > pseudoinverse(T tol=std::numeric_limits< T >::epsilon(), int *rank=nullptr, Vector2< T > *space=nullptr) const
Vector2< T > maxEigenvector() const
computes not-unit eigenvector corresponding to maximum eigenvalue
T xx
zero matrix by default
Definition MRSymMatrix2.h:21
static constexpr Matrix2 fromRows(const Vector2< T > &x, const Vector2< T > &y) noexcept
constructs a matrix from its 2 rows
Definition MRMatrix2.h:52
Color operator+(const Color &a, const Color &b)
Definition MRColor.h:112
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
Definition MRMatrix2.h:24
Definition MRSymMatrix2.h:17
Definition MRVector2.h:29
T x
Definition MRVector2.h:35
T y
Definition MRVector2.h:35