Compare commits

..

4 Commits

Author SHA1 Message Date
fba09a5c40 Added passing a function as parameter 2024-12-30 21:46:11 +01:00
7a2b42e06d Updated gitignore for windows 2024-12-30 21:45:51 +01:00
91348e7c09 Added operations for floats 2024-12-27 23:41:16 +01:00
2d2d6afcfb Delete main.cpp 2024-12-27 23:40:15 +01:00
3 changed files with 31 additions and 15 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
build/*
.vscode/*
main.cpp
main.exe

View File

@ -1,13 +0,0 @@
#include "matrices.h"
int main() {
Matrix a(3, 3);
a.Print("A");
a = a.Add(0.5F);
a.Print("A + 0.5F");
return 0;
}

View File

@ -27,6 +27,8 @@ class Matrix{
inline Matrix Substract(float);
inline Matrix Substract(const Matrix*);
inline Matrix Function(float (*f)(float));
inline void Print(std::string_view);
inline Matrix Transpose();
@ -36,7 +38,10 @@ class Matrix{
inline Matrix operator+(const Matrix*);
inline Matrix operator-(const Matrix*);
inline Matrix operator*(const Matrix*);
// TODO : Add float parameters for these
inline Matrix operator+(float);
inline Matrix operator-(float);
inline Matrix operator*(float);
// Constructors
inline Matrix(int, int);
@ -59,6 +64,29 @@ Matrix Matrix::operator*(const Matrix* other){
return this->Multiply(other);
}
Matrix Matrix::operator+(float value){
return this->Add(value);
}
Matrix Matrix::operator-(float value){
return this->Substract(value);
}
Matrix Matrix::operator*(float value){
return this->Multiply(value);
}
Matrix Matrix::Function(float (*f)(float)){
Matrix result = this;
for(int m = 0; m < result.values.size(); m++){
for(int n = 0; n < result.values[m].size(); n++){
// Execute function on every value
result.values[m][n] = f(result.values[m][n]);
}
}
return result;
}
// Constructs a zero matrix
Matrix::Matrix(int rows, int cols){
for(int m = 0; m < rows; m++){