mirror of
https://gitlab.com/klmp200/LO27.git
synced 2024-11-26 06:54:14 +00:00
Merge branch 'sli' into 'master'
SequenceOnMatrix operations See merge request !11
This commit is contained in:
commit
010f9b0240
@ -225,16 +225,18 @@ void BasicPrintMatrix(Matrix matrix){
|
|||||||
/* Non optimisé : debug fx */
|
/* Non optimisé : debug fx */
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
bool b;
|
||||||
|
|
||||||
printf("\n---PRINT MATRIX---\n");
|
printf("\n---PRINT MATRIX---\n");
|
||||||
|
|
||||||
for (i=0;i<matrix.colCount;i++){
|
for (i=0;i<matrix.rowCount;i++){
|
||||||
printf("| ");
|
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 ");
|
printf("1 ");
|
||||||
}else if (GetCellValue(matrix,i,j) == false){
|
}else if (b == false){
|
||||||
printf("0 ");
|
printf("0 ");
|
||||||
}else{
|
}else{
|
||||||
printf("X "); /* error out of bounds, should never happend*/
|
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 :
|
/* todos :
|
||||||
*finir le freeMatrix
|
*finir le freeMatrix
|
||||||
*chasser les bugs
|
*chasser les bugs
|
||||||
|
@ -131,6 +131,61 @@ bool RecursiveFreeCol(Matrix matrix, cellElement * elem);
|
|||||||
|
|
||||||
Matrix freeMatrix(Matrix matrix);
|
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
|
#endif
|
||||||
|
|
||||||
|
8
main.c
8
main.c
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
int main(int argc, char **argv){
|
int main(int argc, char **argv){
|
||||||
Matrix matrix = CreateMatrix();
|
Matrix matrix = CreateMatrix();
|
||||||
|
Matrix m2;
|
||||||
int Rule = 256;
|
int Rule = 256;
|
||||||
int N = 1;
|
int N = 1;
|
||||||
applyRules(matrix,Rule,N);
|
applyRules(matrix,Rule,N);
|
||||||
@ -28,6 +29,13 @@ int main(int argc, char **argv){
|
|||||||
SetCellValue(matrix,0,1,false);
|
SetCellValue(matrix,0,1,false);
|
||||||
BasicPrintMatrix(matrix);
|
BasicPrintMatrix(matrix);
|
||||||
|
|
||||||
|
m2 = colSequenceOnMatrix(matrix, OR);
|
||||||
|
BasicPrintMatrix(m2);
|
||||||
|
freeMatrix(m2);
|
||||||
|
m2 = rowSequenceOnMatrix(matrix, AND);
|
||||||
|
BasicPrintMatrix(m2);
|
||||||
|
freeMatrix(m2);
|
||||||
|
|
||||||
freeMatrix(matrix);
|
freeMatrix(matrix);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user