11#pragma warning(disable: 4804)
12#pragma warning(disable: 4146)
37 static constexpr Matrix2 scale( T sx, T sy )
noexcept {
return Matrix2( { sx, T(0) }, { T(0), sy } ); }
57 constexpr T
trace() const noexcept {
return x.x +
y.y; }
59 constexpr T
normSq() const noexcept {
return x.lengthSq() +
y.lengthSq(); }
60 constexpr auto norm() const noexcept
68 constexpr T
det() const noexcept;
74 [[nodiscard]] friend constexpr
bool operator ==( const
Matrix2<T> & a, const
Matrix2<T> & b ) {
return a.
x == b.x && a.y == b.y; }
85 if constexpr ( std::is_integral_v<T> )
86 return { b.x / a, b.y / a };
96 if constexpr ( std::is_integral_v<T> )
97 { a.
x /= b; a.y /= b;
return a; }
99 return a *= ( 1 / b );
105 return {
dot( a.x, b ),
dot( a.y, b ) };
112 for (
int i = 0; i < 2; ++i )
113 for (
int j = 0; j < 2; ++j )
114 res[i][j] =
dot( a[i], b.col(j) );
126 return dot( a.x, b.x ) + dot( a.y, b.y );
133 return { a.
x * b, a.
y * b };
150 const auto x =
cross( from, to );
152 return rotation(
angle( from, to ) );
154 return rotation( -
angle( from, to ) );
155 if (
dot( from, to ) >= 0 )
157 return rotation( T( PI ) );
163 return x.x * y.y - x.y * y.x;
169 auto det = this->det();
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:31
MRMESH_CLASS Vector3< double > Matrix2
Definition MRMesh/MRMeshFwd.h:186
int dot(Vector2i a, Vector2i b)
Vector3f cross(Vector3f a, Vector3f b)
Definition MRMatrix2.h:19
constexpr Matrix2(const Matrix2< U > &m)
Definition MRMatrix2.h:31
Vector2< T > x
rows, identity matrix by default
Definition MRMatrix2.h:24
static constexpr Matrix2 rotation(const Vector2< T > &from, const Vector2< T > &to) noexcept
creates matrix representing rotation that after application to (from) makes (to) vector
static constexpr Matrix2 scale(T s) noexcept
returns a matrix that scales uniformly
Definition MRMatrix2.h:35
constexpr T normSq() const noexcept
compute sum of squared matrix elements
Definition MRMatrix2.h:59
Matrix2< T > outer(const Vector2< T > &a, const Vector2< T > &b)
x = a * b^T
Definition MRMatrix2.h:131
auto dot(const Matrix2< T > &a, const Matrix2< T > &b) -> decltype(dot(a.x, b.x))
double-dot product: x = a : b
Definition MRMatrix2.h:124
friend constexpr auto operator/(Matrix2< T > b, T a) -> Matrix2< decltype(std::declval< T >()/std::declval< T >())>
Definition MRMatrix2.h:83
friend constexpr auto operator-(const Matrix2< T > &a, const Matrix2< T > &b) -> Matrix2< decltype(std::declval< T >() - std::declval< T >())>
Definition MRMatrix2.h:80
friend constexpr Matrix2< T > & operator-=(Matrix2< T > &a, const Matrix2< T > &b)
Definition MRMatrix2.h:92
friend constexpr Matrix2< T > & operator*=(Matrix2< T > &a, T b)
Definition MRMatrix2.h:93
static constexpr Matrix2 rotation(T angle) noexcept
creates matrix representing rotation around origin on given angle
constexpr Vector2< T > col(int i) const noexcept
column access
Definition MRMatrix2.h:54
static constexpr Matrix2 identity() noexcept
Definition MRMatrix2.h:33
Vector2< T > y
Definition MRMatrix2.h:25
constexpr Matrix2< T > transposed() const noexcept
computes transposed matrix
T ValueType
Definition MRMatrix2.h:20
constexpr T det() const noexcept
computes determinant of the matrix
friend constexpr auto operator*(T a, const Matrix2< T > &b) -> Matrix2< decltype(std::declval< T >() *std::declval< T >())>
Definition MRMatrix2.h:81
static constexpr Matrix2 scale(const Vector2< T > &s) noexcept
Definition MRMatrix2.h:38
friend constexpr Matrix2< T > & operator+=(Matrix2< T > &a, const Matrix2< T > &b)
Definition MRMatrix2.h:91
static constexpr Matrix2 scale(T sx, T sy) noexcept
returns a matrix that has its own scale along each axis
Definition MRMatrix2.h:37
constexpr T trace() const noexcept
computes trace of the matrix
Definition MRMatrix2.h:57
constexpr const Vector2< T > & operator[](int row) const noexcept
row access
Definition MRMatrix2.h:50
constexpr Matrix2() noexcept=default
friend constexpr bool operator!=(const Matrix2< T > &a, const Matrix2< T > &b)
Definition MRMatrix2.h:75
constexpr Matrix2< T > inverse() const noexcept
computes inverse matrix
friend constexpr Matrix2< T > & operator/=(Matrix2< T > &a, T b)
Definition MRMatrix2.h:94
constexpr auto norm() const noexcept
Definition MRMatrix2.h:60
static constexpr Matrix2 zero() noexcept
Definition MRMatrix2.h:32
friend constexpr auto operator+(const Matrix2< T > &a, const Matrix2< T > &b) -> Matrix2< decltype(std::declval< T >()+std::declval< T >())>
Definition MRMatrix2.h:79
static constexpr Matrix2 fromRows(const Vector2< T > &x, const Vector2< T > &y) noexcept
constructs a matrix from its 2 rows
Definition MRMatrix2.h:44
static constexpr Matrix2 fromColumns(const Vector2< T > &x, const Vector2< T > &y) noexcept
Definition MRMatrix2.h:47
Definition MRVector2.h:25
T x
Definition MRVector2.h:31
T y
Definition MRVector2.h:31