D2A62006 2025-11-26 18:33:33 +01:00
commit 5ce0982e17

View File

@ -76,7 +76,9 @@ void clearMatrix(Matrix *matrix)
{ {
for (int i = 0; i < matrix->rows; i++) { for (int i = 0; i < matrix->rows; i++) {
for (int j = 0; j < matrix->cols;j++) { for (int j = 0; j < matrix->cols;j++) {
matrix->buffer[i + matrix->rows * j] = UNDEFINED_MATRIX_VALUE; // Normally one would expect to work matrices like this, but it is supposed to be the other way around.
// matrix->buffer[i + matrix->rows * j] = UNDEFINED_MATRIX_VALUE;
matrix->buffer[j + matrix->cols * i] = UNDEFINED_MATRIX_VALUE;
} }
} }
free(matrix->buffer); free(matrix->buffer);
@ -88,7 +90,11 @@ 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)
{ {
//checks, if the given incies are allowed //checks, if the given incies are allowed
if((rowIdx) < matrix.rows && (colIdx) < matrix.cols) matrix.buffer[rowIdx + matrix.rows*(colIdx)] = value; if((rowIdx) < matrix.rows && (colIdx) < matrix.cols) {
// Normally one would expect to work matrices like this, but it is supposed to be the other way around.
// matrix.buffer[rowIdx + matrix.rows*(colIdx)] = value;
matrix.buffer[colIdx + matrix.cols * rowIdx] = value;
}
} }
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
@ -96,7 +102,9 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
//checks, if the given indices are allowed //checks, if the given indices are allowed
if((rowIdx) < matrix.rows && (colIdx) < matrix.cols) { if((rowIdx) < matrix.rows && (colIdx) < matrix.cols) {
MatrixType returnVal; MatrixType returnVal;
returnVal = matrix.buffer[rowIdx + matrix.rows*(colIdx)]; // Normally one would expect to work matrices like this, but it is supposed to be the other way around.
// returnVal = matrix.buffer[rowIdx + matrix.rows*(colIdx)];
returnVal = matrix.buffer[colIdx + rowIdx * matrix.cols];
return returnVal; return returnVal;
} }
else return 0; else return 0;