13#pragma warning(disable: 4804)
14#pragma warning(disable: 4146)
42 static constexpr Matrix2 scale( T sx, T sy )
noexcept {
return Matrix2( { sx, T(0) }, { T(0), sy } ); }
62 constexpr T
trace() const noexcept {
return x.x +
y.y; }
64 constexpr T
normSq() const noexcept {
return x.lengthSq() +
y.lengthSq(); }
65 constexpr auto norm() const noexcept
73 constexpr T
det() const noexcept;
79 [[nodiscard]] friend constexpr
bool operator ==( const
Matrix2<T> & a, const
Matrix2<T> & b ) {
return a.
x == b.x && a.y == b.y; }
90 if constexpr ( std::is_integral_v<T> )
91 return { b.x / a, b.y / a };
101 if constexpr ( std::is_integral_v<T> )
102 { a.
x /= b; a.
y /= b;
return a; }
104 return a *= ( 1 / b );
110 return {
dot( a.x, b ),
dot( a.y, b ) };
117 for (
int i = 0; i < 2; ++i )
118 for (
int j = 0; j < 2; ++j )
119 res[i][j] =
dot( a[i], b.col(j) );
125 return s << mat.
x <<
'\n' << mat.
y <<
'\n';
130 return s >> mat.
x >> mat.
y;
141 return dot( a.x, b.x ) + dot( a.y, b.y );
148 return { a.
x * b, a.
y * b };
163constexpr Matrix2<T> Matrix2<T>::rotation(
const Vector2<T> & from,
const Vector2<T> & to )
noexcept MR_REQUIRES_IF_SUPPORTED( std::is_floating_point_v<T> )
165 const auto x =
cross( from, to );
167 return rotation(
angle( from, to ) );
169 return rotation( -
angle( from, to ) );
170 if (
dot( from, to ) >= 0 )
172 return rotation( T( PI ) );
178 return x.x * y.y - x.y * y.x;
184 auto det = this->det();
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:34
Definition MRCameraOrientationPlugin.h:8
float dot(Vector2f a, Vector2f b)
float cross(Vector2f a, Vector2f b)
Definition MRMatrix2.h:21
constexpr Matrix2(const Matrix2< U > &m)
Definition MRMatrix2.h:36
Vector2< T > x
rows, identity matrix by default
Definition MRMatrix2.h:26
constexpr Matrix2() noexcept
Definition MRMatrix2.h:29
static constexpr Matrix2 scale(T s) noexcept
returns a matrix that scales uniformly
Definition MRMatrix2.h:40
constexpr T normSq() const noexcept
compute sum of squared matrix elements
Definition MRMatrix2.h:64
Matrix2< T > outer(const Vector2< T > &a, const Vector2< T > &b)
x = a * b^T
Definition MRMatrix2.h:146
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:139
friend std::ostream & operator<<(std::ostream &s, const Matrix2 &mat)
Definition MRMatrix2.h:123
static constexpr Matrix2 static rotation(T angle) noexcept MR_REQUIRES_IF_SUPPORTED(std constexpr Matrix2 static rotation(const Vector2< T > &from, const Vector2< T > &to) noexcept MR_REQUIRES_IF_SUPPORTED(std constexpr Matrix fromRows)(const Vector2< T > &x, const Vector2< T > &y) noexcept
creates matrix representing rotation around origin on given angle
Definition MRMatrix2.h:49
friend constexpr auto operator/(Matrix2< T > b, T a) -> Matrix2< decltype(std::declval< T >()/std::declval< T >())>
Definition MRMatrix2.h:88
friend constexpr auto operator-(const Matrix2< T > &a, const Matrix2< T > &b) -> Matrix2< decltype(std::declval< T >() - std::declval< T >())>
Definition MRMatrix2.h:85
constexpr Matrix2(const Vector2< T > &x, const Vector2< T > &y)
initializes matrix from its 2 rows
Definition MRMatrix2.h:34
friend constexpr Matrix2< T > & operator-=(Matrix2< T > &a, const Matrix2< T > &b)
Definition MRMatrix2.h:97
friend constexpr Matrix2< T > & operator*=(Matrix2< T > &a, T b)
Definition MRMatrix2.h:98
constexpr Vector2< T > col(int i) const noexcept
column access
Definition MRMatrix2.h:59
static constexpr Matrix2 identity() noexcept
Definition MRMatrix2.h:38
Vector2< T > y
Definition MRMatrix2.h:27
T ValueType
Definition MRMatrix2.h:22
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:86
static constexpr Matrix2 scale(const Vector2< T > &s) noexcept
Definition MRMatrix2.h:43
friend constexpr Matrix2< T > & operator+=(Matrix2< T > &a, const Matrix2< T > &b)
Definition MRMatrix2.h:96
static constexpr Matrix2 scale(T sx, T sy) noexcept
returns a matrix that has its own scale along each axis
Definition MRMatrix2.h:42
friend std::istream & operator>>(std::istream &s, Matrix2 &mat)
Definition MRMatrix2.h:128
constexpr T trace() const noexcept
computes trace of the matrix
Definition MRMatrix2.h:62
constexpr const Vector2< T > & operator[](int row) const noexcept
row access
Definition MRMatrix2.h:55
friend constexpr bool operator!=(const Matrix2< T > &a, const Matrix2< T > &b)
Definition MRMatrix2.h:80
constexpr Matrix2< T > inverse() const noexcept MR_REQUIRES_IF_SUPPORTED(std constexpr Matrix2< T > transposed() const noexcept
computes inverse matrix
friend constexpr Matrix2< T > & operator/=(Matrix2< T > &a, T b)
Definition MRMatrix2.h:99
constexpr auto norm() const noexcept
Definition MRMatrix2.h:65
static constexpr Matrix2 zero() noexcept
Definition MRMatrix2.h:37
friend constexpr auto operator+(const Matrix2< T > &a, const Matrix2< T > &b) -> Matrix2< decltype(std::declval< T >()+std::declval< T >())>
Definition MRMatrix2.h:84
static constexpr Matrix2 fromColumns(const Vector2< T > &x, const Vector2< T > &y) noexcept
Definition MRMatrix2.h:52
Definition MRVector2.h:29
T x
Definition MRVector2.h:35
T y
Definition MRVector2.h:35