diff --git a/Startcode/matrix.c b/Startcode/matrix.c index d926c4f..b68a73b 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -42,11 +42,22 @@ void clearMatrix(Matrix *matrix) void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + if(matrix.rows <= rowIdx || matrix.cols <= colIdx) { + return; + } + unsigned int index = rowIdx * matrix.cols + colIdx; + + matrix.buffer[index] = value; } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { + if(matrix.rows <= rowIdx || matrix.cols <= colIdx){ + return UNDEFINED_MATRIX_VALUE; + } + unsigned int index = rowIdx * matrix.cols + colIdx; + + return matrix.buffer[index]; }