c_physics_engine
A custom physics engine written in C/C++
|
#include <matrix.hpp>
Public Member Functions | |
Matrix (std::size_t rows, std::size_t cols=1) | |
Constructs a Matrix with the specified number of rows and columns. | |
std::pair< std::size_t, std::size_t > | Shape () const |
return the shape of the matrix as a tuple of (rows, cols). | |
float | Get (std::size_t row, std::size_t col) const |
Retrieves a value from the matrix at the specified row and column. | |
void | applyFunction (std::function< float(float)> func) |
Apply a function to all elements of the matrix. | |
Matrix | Submatrix (std::size_t rows, std::size_t cols, std::size_t row_start, std::size_t col_start) const |
Extract a submatrix from the matrix. | |
float | Sum () const |
Sum all elements in the matrix. | |
Matrix | memwise_iMul (const Matrix &other) |
Memberwise-multiply a matrix to this one. | |
Matrix | memwise_iDiv (const Matrix &other) |
Memberwise-divide this matrix by anoter one. | |
Matrix | operator+= (const Matrix &other) |
Add another matrix to this one. | |
Matrix | operator+ (const Matrix &other) const |
Add two matrices. | |
Matrix | operator-= (const Matrix &other) |
Subtract another matrix from this one. | |
Matrix | operator- (const Matrix &other) const |
Subtract two matrices. | |
Matrix | operator*= (const Matrix &other) |
Multiply another matrix to this one. | |
Matrix | operator* (const Matrix &other) const |
Multiply two matrices. | |
Matrix | operator*= (float scalar) |
Scale this matrix. | |
Matrix | operator* (float scalar) const |
Scale a matrix. | |
Matrix | operator/= (float scalar) |
Divide this matrix by a scalar. | |
Matrix | operator/ (float scalar) const |
Divide a matrix by a scalar. | |
Matrix | operator= (const Matrix &other) |
Copy this matrix. | |
Matrix | operator- () const |
Negate this matrix. | |
Matrix | operator! () const |
Transpose this matrix. | |
float & | operator[] (std::size_t row, std::size_t col) |
Access values inside the matrix. | |
bool | operator== (const Matrix &other) |
Check if this matrices is equal to another matrix. | |
bool | operator!= (const Matrix &other) |
Check if this matrices is different from another matrix. | |
Static Public Member Functions | |
static Matrix | Identity (std::size_t size) |
Creates a new identity-matrix. | |
static Matrix | Combine (std::vector< Matrix > matrices, bool vertical=false) |
Combine multiple matrices into a new matrix. | |
static Matrix | memwise_Mul (const Matrix &lhs, const Matrix &rhs) |
Memberwise-multiply two matrices. | |
static Matrix | memwise_Div (const Matrix &lhs, const Matrix &rhs) |
Memberwise-divide two matrices. | |
cpp_physics::Matrix::Matrix | ( | std::size_t | rows, |
std::size_t | cols = 1 ) |
Constructs a Matrix with the specified number of rows and columns.
rows | The number of rows in the matrix. |
cols | The number of columns in the matrix. Defaults to 1. |
void cpp_physics::Matrix::applyFunction | ( | std::function< float(float)> | func | ) |
Apply a function to all elements of the matrix.
func | A function that takes a float as Argument and return a float. |
|
static |
Combine multiple matrices into a new matrix.
matrices | A vector containing the matrices to combine. |
vertical | Align the matrices horizontally or vertically. Defaults to false, for horizontal. |
float cpp_physics::Matrix::Get | ( | std::size_t | row, |
std::size_t | col ) const |
Retrieves a value from the matrix at the specified row and column.
row | The row index from which to retrieve the value. |
col | The column index from which to retrieve the value. |
|
static |
Creates a new identity-matrix.
size | Amount o frows and columns in the Matrix |
Memberwise-divide two matrices.
lhs | The dividend. |
rhs | The divisor. |
Memberwise-divide this matrix by anoter one.
other | The divisor. |
Memberwise-multiply a matrix to this one.
other | The multiplier. |
Memberwise-multiply two matrices.
lhs | The multiplicand. |
rhs | The multiplier. |
Matrix cpp_physics::Matrix::operator! | ( | ) | const |
Transpose this matrix.
bool cpp_physics::Matrix::operator!= | ( | const Matrix & | other | ) |
Check if this matrices is different from another matrix.
other | The matrix to compare to. |
Multiply two matrices.
other | The multiplier. |
Matrix cpp_physics::Matrix::operator* | ( | float | scalar | ) | const |
Scale a matrix.
scalar | The scalar to scale by. |
Multiply another matrix to this one.
other | The matrix to multiply with. |
Matrix cpp_physics::Matrix::operator*= | ( | float | scalar | ) |
Scale this matrix.
scalar | The factor to scale the matrix by. |
Add two matrices.
other | The addend. |
Add another matrix to this one.
other | The matrix to add. |
Matrix cpp_physics::Matrix::operator- | ( | ) | const |
Negate this matrix.
Subtract two matrices.
other | The subtrahend. |
Subtract another matrix from this one.
other | The matrix to subtract. |
Matrix cpp_physics::Matrix::operator/ | ( | float | scalar | ) | const |
Divide a matrix by a scalar.
scalar | The scalar to divide by. |
Matrix cpp_physics::Matrix::operator/= | ( | float | scalar | ) |
Divide this matrix by a scalar.
scalar | The factor to divide the matrix by. |
Copy this matrix.
other | The matrix to copy. |
bool cpp_physics::Matrix::operator== | ( | const Matrix & | other | ) |
Check if this matrices is equal to another matrix.
other | The matrix to compare to. |
float & cpp_physics::Matrix::operator[] | ( | std::size_t | row, |
std::size_t | col ) |
Access values inside the matrix.
row | The row of the value to access. |
col | The row of the value to access. |
std::pair< std::size_t, std::size_t > cpp_physics::Matrix::Shape | ( | ) | const |
return the shape of the matrix as a tuple of (rows, cols).
Matrix cpp_physics::Matrix::Submatrix | ( | std::size_t | rows, |
std::size_t | cols, | ||
std::size_t | row_start, | ||
std::size_t | col_start ) const |
Extract a submatrix from the matrix.
rows | Amount of rows in the submatrix. |
cols | Amount of columns in the submatrix. |
row_start | The starting row index for the submatrix. |
col_start | The starting column index for the submatrix. |
float cpp_physics::Matrix::Sum | ( | ) | const |
Sum all elements in the matrix.