set and get
This commit is contained in:
parent
f3398f9ea0
commit
4d6daf5b6f
13
matrix.c
13
matrix.c
@ -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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
runMatrixTests
BIN
runMatrixTests
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user