Regina 7.0 Calculation Engine
|
Represents a 2-by-2 integer matrix. More...
#include <maths/matrix2.h>
Public Member Functions | |
Matrix2 () | |
Initialises to the zero matrix. More... | |
Matrix2 (const Matrix2 &)=default | |
Initialises to a copy of the given matrix. More... | |
Matrix2 (const long values[2][2]) | |
Deprecated constructor that initialises to the given integer values. More... | |
Matrix2 (long val00, long val01, long val10, long val11) | |
Initialises to the given integer values. More... | |
Matrix2 & | operator= (const Matrix2 &)=default |
Sets this matrix to be a copy of the given matrix. More... | |
Matrix2 & | operator= (const long values[2][2]) |
Deprecated routine that sets the elements of this matrix to the given integer values. More... | |
void | swap (Matrix2 &other) noexcept |
Swaps the contents of this and the given matrix. More... | |
const std::array< long, 2 > & | operator[] (unsigned row) const |
Returns a single row of this matrix. More... | |
std::array< long, 2 > & | operator[] (unsigned row) |
Returns a single row of this matrix. More... | |
Matrix2 | operator* (const Matrix2 &other) const |
Calculates the matrix product of this and the given matrix. More... | |
Matrix2 | operator* (long scalar) const |
Calculates the scalar product of this matrix and the given integer. More... | |
Matrix2 | operator+ (const Matrix2 &other) const |
Calculates the sum of two matrices. More... | |
Matrix2 | operator- (const Matrix2 &other) const |
Calculates the difference of two matrices. More... | |
Matrix2 | operator- () const |
Determines the negative of this matrix. More... | |
Matrix2 | transpose () const |
Returns the transpose of this matrix. More... | |
Matrix2 | inverse () const |
Calculates the inverse of this matrix. More... | |
Matrix2 & | operator+= (const Matrix2 &other) |
Adds the given matrix to this. More... | |
Matrix2 & | operator-= (const Matrix2 &other) |
Subtracts the given matrix from this. More... | |
Matrix2 & | operator*= (const Matrix2 &other) |
Multiplies this by the given matrix. More... | |
Matrix2 & | operator*= (long scalar) |
Multiplies this by the given scalar. More... | |
void | negate () |
Negates this matrix. More... | |
bool | invert () |
Inverts this matrix. More... | |
bool | operator== (const Matrix2 &compare) const |
Determines if this is equal to the given matrix. More... | |
bool | operator!= (const Matrix2 &compare) const |
Determines if this is not equal to the given matrix. More... | |
long | determinant () const |
Returns the determinant of this matrix. More... | |
bool | isIdentity () const |
Determines if this is the 2x2 identity matrix. More... | |
bool | isZero () const |
Determines if this is the 2x2 zero matrix. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &out, const Matrix2 &mat) |
Writes the given matrix to the given output stream. More... | |
Represents a 2-by-2 integer matrix.
The advantage of using this class over the larger Matrix class template (e.g., MatrixInt) is that this class has less overhead.
This class only contains four long integers, and so it may be considered small enough to pass about by value.
This class supports copying but does not implement separate move operations, since its internal data is so small that copying is just as efficient. It implements the C++ Swappable requirement via its own member and global swap() functions, for consistency with the Matrix classes.
|
inline |
Initialises to the zero matrix.
|
default |
Initialises to a copy of the given matrix.
|
inline |
Deprecated constructor that initialises to the given integer values.
Each given integer values[r][c]
will be placed in row r, column c.
values | the four values to insert into the new matrix. |
|
inline |
Initialises to the given integer values.
val00 | the value to place in row 0, column 0. |
val01 | the value to place in row 0, column 1. |
val10 | the value to place in row 1, column 0. |
val11 | the value to place in row 1, column 1. |
|
inline |
Returns the determinant of this matrix.
Matrix2 regina::Matrix2::inverse | ( | ) | const |
Calculates the inverse of this matrix.
This matrix is not changed.
This routine only works for integer matrices whose determinant is either +1 or -1.
bool regina::Matrix2::invert | ( | ) |
Inverts this matrix.
This routine only works for integer matrices whose determinant is either +1 or -1. Otherwise this matrix is left unchanged.
true
if this matrix was successfully inverted (i.e., its determinant was +1 or -1), or false
otherwise.
|
inline |
Determines if this is the 2x2 identity matrix.
true
if this is the identity matrix, or false
otherwise.
|
inline |
Determines if this is the 2x2 zero matrix.
true
if this is the zero matrix, or false
otherwise.
|
inline |
Negates this matrix.
This matrix is changed to reflect the result.
|
inline |
Determines if this is not equal to the given matrix.
compare | the matrix with which this will be compared. |
true
if and only if this matrix is not equal to compare. Calculates the matrix product of this and the given matrix.
Neither this nor the given matrix is changed.
other | the matrix that this should be multiplied by. |
|
inline |
Calculates the scalar product of this matrix and the given integer.
This matrix is not changed.
scalar | the integer that this matrix should be multiplied by. |
Multiplies this by the given matrix.
This matrix is changed to reflect the result.
other | the matrix by which this should be multiplied. |
|
inline |
Multiplies this by the given scalar.
This matrix is changed to reflect the result.
scalar | the scalar by which this should be multiplied. |
Calculates the sum of two matrices.
Neither this nor the given matrix is changed.
other | the matrix to add to this. |
Adds the given matrix to this.
This matrix is changed to reflect the result.
other | the matrix to add to this. |
|
inline |
Determines the negative of this matrix.
This matrix is not changed.
Calculates the difference of two matrices.
Neither this nor the given matrix is changed.
other | the matrix to subtract from this. |
Subtracts the given matrix from this.
This matrix is changed to reflect the result.
other | the matrix to subtract from this. |
|
inline |
Deprecated routine that sets the elements of this matrix to the given integer values.
Each given integer values[r][c]
will be placed in row r, column c.
values | the four values to copy into this matrix. |
Sets this matrix to be a copy of the given matrix.
|
inline |
Determines if this is equal to the given matrix.
compare | the matrix with which this will be compared. |
true
if and only if this matrix is equal to compare.
|
inline |
Returns a single row of this matrix.
This means that the integer in row r, column c can be accessed as myMatrix[r][c]
(where r and c are each 0 or 1). Each such element may be modified directly.
row | the index of the requested row; this must be 0 or 1. |
|
inline |
Returns a single row of this matrix.
This means that the integer in row r, column c can be accessed as myMatrix[r][c]
(where r and c are each 0 or 1).
row | the index of the requested row; this must be 0 or 1. |
|
inlinenoexcept |
Swaps the contents of this and the given matrix.
other | the matrix whose contents should be swapped with this. |
|
inline |
Returns the transpose of this matrix.
This matrix is not changed.
|
friend |
Writes the given matrix to the given output stream.
The matrix will be written entirely on a single line, with the first row followed by the second row.
out | the output stream to which to write. |
mat | the matrix to write. |