12#if __cpp_constexpr >= 201304
13# define CONSTEXPR14 constexpr
15# define CONSTEXPR14 inline
28 template <
typename T1,
typename T2 = T1>
class Matrix2 {
40 constexpr Matrix2(T1
x, T2
y) noexcept : _x{std::move(
x)}, _y{std::move(
y)} {}
47 constexpr auto x() const -> const T1& {
return this->_x; }
54 constexpr auto y() const -> const T2& {
return this->_y; }
84 template <
typename U1,
typename U2>
86 this->_x += other.
x();
87 this->_y += other.y();
99 template <
typename U1,
typename U2>
101 this->_x -= other.
x();
102 this->_y -= other.y();
141 template <
typename U1,
typename U2>
144 return std::move(
x) +=
y;
156 template <
typename U1,
typename U2>
159 return std::move(
x) -=
y;
216 template <
typename U1,
typename U2>
218 return T1{this->_x.dot(other), this->_y.dot(other)};
231 constexpr auto det() const ->
double {
232 return this->
x().x() * this->
y().y() - this->
x().y() * this->
y().x();
Matrix2.
Definition matrix2.hpp:28
constexpr auto x() const -> const T1 &
Get the first column vector.
Definition matrix2.hpp:47
CONSTEXPR14 auto operator-=(const Matrix2< U1, U2 > &other) -> Matrix2< T1, T2 > &
Subtract another matrix from this one.
Definition matrix2.hpp:100
CONSTEXPR14 auto operator+=(const Matrix2< U1, U2 > &other) -> Matrix2< T1, T2 > &
Add another matrix to this one.
Definition matrix2.hpp:85
friend constexpr auto operator/(Matrix2< T1, T2 > x, const R &alpha) -> Matrix2< T1, T2 >
Divide matrix by a scalar.
Definition matrix2.hpp:196
friend constexpr auto operator+(Matrix2< T1, T2 > x, const Matrix2< U1, U2 > &y) -> Matrix2< T1, T2 >
Add two matrices.
Definition matrix2.hpp:142
friend constexpr auto operator*(Matrix2< T1, T2 > x, const R &alpha) -> Matrix2< T1, T2 >
Multiply matrix by a scalar.
Definition matrix2.hpp:170
constexpr Matrix2(T1 x, T2 y) noexcept
Construct a new Matrix2 object.
Definition matrix2.hpp:40
constexpr auto y() const -> const T2 &
Get the second column vector.
Definition matrix2.hpp:54
friend constexpr auto operator*(const R &alpha, Matrix2< T1, T2 > x) -> Matrix2< T1, T2 >
Multiply a scalar by a matrix.
Definition matrix2.hpp:183
constexpr auto mdot(const Vector2< U1, U2 > &other) const -> T1
Multiply matrix with vector.
Definition matrix2.hpp:217
CONSTEXPR14 auto operator*=(const R &alpha) -> Matrix2< T1, T2 > &
Multiply.
Definition matrix2.hpp:113
constexpr auto operator-() const -> Matrix2< T1, T2 >
Negate the matrix.
Definition matrix2.hpp:74
friend constexpr auto operator-(Matrix2< T1, T2 > x, const Matrix2< U1, U2 > &y) -> Matrix2< T1, T2 >
Subtract two matrices.
Definition matrix2.hpp:157
CONSTEXPR14 auto operator/=(const R &alpha) -> Matrix2< T1, T2 > &
Divide matrix by a scalar.
Definition matrix2.hpp:126
constexpr auto det() const -> double
Calculate the determinant.
Definition matrix2.hpp:231
Vector2.
Definition vector2.hpp:19
#define CONSTEXPR14
Definition matrix2.hpp:15