set and get

This commit is contained in:
Your Name 2026-05-06 06:26:14 +02:00
parent f3398f9ea0
commit 4d6daf5b6f
2 changed files with 11 additions and 2 deletions

View File

@ -31,12 +31,21 @@ void clearMatrix(Matrix *matrix)
} }
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
{ { if (rowIdx >= matrix.rows || colIdx >= matrix.cols){ // check if indices are valid
return; // do nothing if out of bounds
}
unsigned int index = rowIdx * matrix.cols + colIdx; // calculate index using row-major formula
matrix.buffer[index] = value ; // set value at that index
} }
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
{ { if (rowIdx >= matrix.rows || colIdx >= matrix.cols){ //check if indices are valid
return UNDEFINED_MATRIX_VALUE;
}
unsigned int index = rowIdx * matrix.cols + colIdx; //calculate index using row-major formula
return matrix.buffer [index]; // return the value at that index
} }

Binary file not shown.