1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-22 22:13:19 +00:00

SequenceOnMatrix operations

This commit is contained in:
Antoine Bartuccio 2016-12-26 20:44:39 +01:00
parent b063bc42c0
commit f327f1024b
3 changed files with 153 additions and 19 deletions

View File

@ -225,16 +225,18 @@ void BasicPrintMatrix(Matrix matrix){
/* Non optimisé : debug fx */
int i = 0;
int j = 0;
bool b;
printf("\n---PRINT MATRIX---\n");
for (i=0;i<matrix.colCount;i++){
for (i=0;i<matrix.rowCount;i++){
printf("| ");
for (j=0;j<matrix.rowCount;j++){
for (j=0;j<matrix.colCount;j++){
if (GetCellValue(matrix,i,j) == true){
b = GetCellValue(matrix,j,i);
if (b == true){
printf("1 ");
}else if (GetCellValue(matrix,i,j) == false){
}else if (b == false){
printf("0 ");
}else{
printf("X "); /* error out of bounds, should never happend*/
@ -311,6 +313,75 @@ Matrix freeMatrix(Matrix matrix){
}
Matrix colSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)){
bool a;
bool b;
int i;
int j;
Matrix newM = CreateMatrix();
newM.rowCount = m.rowCount;
if (m.colCount <= 1){
newM.colCount = 0;
return newM;
}
newM.colCount = m.colCount - 1;
for (i=0;i < m.colCount - 1;i++){
for (j=0;j < m.rowCount;j++){
a = GetCellValue(m, i, j);
b = GetCellValue(m, i + 1, j);
if (operator(a, b)){
SetCellValue(newM, i, j, true);
}
}
}
return newM;
}
Matrix rowSequenceOnMatrix(Matrix m, bool (operator)(bool, bool)){
bool a;
bool b;
int i;
int j;
Matrix newM = CreateMatrix();
newM.colCount = m.colCount;
if (m.rowCount <= 1){
newM.rowCount = 0;
return newM;
}
newM.rowCount = m.rowCount - 1;
for (i=0; i < m.colCount;i++){
for (j=0;j < m.rowCount - 1;j++){
a = GetCellValue(m, i, j);
b = GetCellValue(m, i, j + 1);
if (operator(a, b)){
SetCellValue(newM, i, j, true);
}
}
}
return newM;
}
Matrix andColSequenceOnMatrix(Matrix m){
return colSequenceOnMatrix(m, AND);
}
Matrix orColSequenceOnMatrix(Matrix m){
return colSequenceOnMatrix(m, OR);
}
Matrix andRowSequenceOnMatrix(Matrix m){
return rowSequenceOnMatrix(m, AND);
}
Matrix orRowSequenceOnMatrix(Matrix m){
return rowSequenceOnMatrix(m, OR);
}
/* todos :
*finir le freeMatrix
*chasser les bugs

View File

@ -131,6 +131,61 @@ bool RecursiveFreeCol(Matrix matrix, cellElement * elem);
Matrix freeMatrix(Matrix matrix);
/**
* Given an input matrix with M rows and N columns, computes a matrix with
* M rows and N-1 columns were each element corresponds to the operator boolean operation
* between two successive horizontal elements in the input matrix
* @param m a Matrix
* @param operator a function
* @return matrix the copmuted matrix
*/
Matrix colSequenceOnMatrix(Matrix m, bool (operator)(bool, bool));
/**
* Given an input matrix with M rows and N columns, computes a matrix with
* M-1 rows and N columns were each element corresponds to the operator boolean operation
* between two succesive vertical elements in the input matrix
* @param m a Matrix
* @param operator a function
* @return matrix the copmuted matrix
*/
Matrix rowSequenceOnMatrix(Matrix m, bool (operator)(bool, bool));
/**
* Given an input matrix with M rows and N columns, computes a matrix with
* M rows and N-1 columns were each element corresponds to the AND boolean operation
* between two successive horizontal elements in the input matrix
* @param m a Matrix
* @return matrix the copmuted matrix
*/
Matrix andColSequenceOnMatrix(Matrix m);
/**
* Given an input matrix with M rows and N columns, computes a matrix with
* M rows and N-1 columns were each element corresponds to the OR boolean operation
* between two successive horizontal elements in the input matrix
* @param m a Matrix
* @return matrix the copmuted matrix
*/
Matrix orColSequenceOnMatrix(Matrix m);
/**
* Given an input matrix with M rows and N columns, computes a matrix with
* M-1 rows and N columns were each element corresponds to the AND boolean operation
* between two succesive vertical elements in the input matrix
* @param m a Matrix
* @return matrix the copmuted matrix
*/
Matrix andRowSequenceOnMatrix(Matrix m);
/**
* Given an input matrix with M rows and N columns, computes a matrix with
* M-1 rows and N columns were each element corresponds to the OR boolean operation
* between two succesive vertical elements in the input matrix
* @param m a Matrix
* @return matrix the copmuted matrix
*/
Matrix orRowSequenceOnMatrix(Matrix m);
#endif

8
main.c
View File

@ -12,6 +12,7 @@
int main(int argc, char **argv){
Matrix matrix = CreateMatrix();
Matrix m2;
int Rule = 256;
int N = 1;
applyRules(matrix,Rule,N);
@ -28,6 +29,13 @@ int main(int argc, char **argv){
SetCellValue(matrix,0,1,false);
BasicPrintMatrix(matrix);
m2 = colSequenceOnMatrix(matrix, OR);
BasicPrintMatrix(m2);
freeMatrix(m2);
m2 = rowSequenceOnMatrix(matrix, AND);
BasicPrintMatrix(m2);
freeMatrix(m2);
freeMatrix(matrix);
return 0;