diff --git a/Startcode/matrix.c b/Startcode/matrix.c index e8498e1..0861687 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -10,9 +10,9 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) matrix.rows = rows; matrix.cols = cols; - matrix.data = calloc(rows * cols, sizeof(MatrixType)); + matrix.buffer = calloc(rows * cols, sizeof(MatrixType)); - if (matrix.data == NULL) + if (matrix.buffer == NULL) { matrix.rows = 0; matrix.cols = 0; @@ -26,9 +26,9 @@ void clearMatrix(Matrix* matrix) { if (matrix != NULL) { - free(matrix->data); + free(matrix->buffer); - matrix->data = NULL; + matrix->buffer = NULL; matrix->rows = 0; matrix->cols = 0; } @@ -38,11 +38,11 @@ void clearMatrix(Matrix* matrix) void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - if (matrix.data != NULL && + if (matrix.buffer != NULL && rowIdx < matrix.rows && colIdx < matrix.cols) { - matrix.data[rowIdx * matrix.cols + colIdx] = value; + matrix.buffer[rowIdx * matrix.cols + colIdx] = value; } } @@ -50,11 +50,11 @@ void setMatrixAt(MatrixType value, Matrix matrix, MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - if (matrix.data != NULL && + if (matrix.buffer != NULL && rowIdx < matrix.rows && colIdx < matrix.cols) { - return matrix.data[rowIdx * matrix.cols + colIdx]; + return matrix.buffer[rowIdx * matrix.cols + colIdx]; } return UNDEFINED_MATRIX_VALUE; @@ -65,15 +65,15 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) { if (matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols || - matrix1.data == NULL || - matrix2.data == NULL) + matrix1.buffer == NULL || + matrix2.buffer == NULL) { return createMatrix(0, 0); } Matrix result = createMatrix(matrix1.rows, matrix1.cols); - if (result.data == NULL) + if (result.buffer == NULL) { return result; } @@ -97,15 +97,15 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) Matrix multiply(const Matrix matrix1, const Matrix matrix2) { if (matrix1.cols != matrix2.rows || - matrix1.data == NULL || - matrix2.data == NULL) + matrix1.buffer == NULL || + matrix2.buffer == NULL) { return createMatrix(0, 0); } Matrix result = createMatrix(matrix1.rows, matrix2.cols); - if (result.data == NULL) + if (result.buffer == NULL) { return result; } diff --git a/Startcode/matrix.h b/Startcode/matrix.h index e6fd8cd..3b8340b 100644 --- a/Startcode/matrix.h +++ b/Startcode/matrix.h @@ -6,7 +6,7 @@ typedef float MatrixType; typedef struct { - MatrixType *data; + MatrixType *buffer; unsigned int rows; unsigned int cols; } Matrix;