mirror of
				https://gitlab.com/klmp200/LO27.git
				synced 2025-10-31 14:53:04 +00:00 
			
		
		
		
	left/right/top/down rules
This commit is contained in:
		| @@ -153,3 +153,18 @@ bool AND(bool a, bool b){ | ||||
| 		return false; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool XOR(bool a, bool b){ | ||||
| 	if (!(a && b) && (a||b)){ | ||||
| 		return true; | ||||
| 	} else { | ||||
| 		return false; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool ErrorToFalse(bool x){ | ||||
| 	if (x == ERROR){ | ||||
| 		return false; | ||||
| 	} | ||||
| 	return x; | ||||
| } | ||||
|   | ||||
| @@ -161,4 +161,19 @@ bool OR(bool a, bool b); | ||||
| */ | ||||
| bool AND(bool a, bool b); | ||||
|  | ||||
| /** | ||||
| * Apply XOR operator to a bool a and a bool b | ||||
| * @param a a bool | ||||
| * @param b a bool | ||||
| * @return result a and b | ||||
| */ | ||||
| bool XOR(bool a, bool b); | ||||
|  | ||||
| /** | ||||
| * Return false if the bool is ERROR | ||||
| * @param x a bool | ||||
| * @return result a bool | ||||
| */ | ||||
| bool ErrorToFalse(bool x); | ||||
|  | ||||
| #endif | ||||
|   | ||||
| @@ -474,6 +474,104 @@ void FreeBooleanMatrix(BooleanMatrix matrix){ | ||||
| 	free(matrix.data); | ||||
| } | ||||
|  | ||||
|  | ||||
| Matrix basicRule(Matrix m, int incrh, int incrv){ | ||||
| 	int i; | ||||
| 	int j; | ||||
| 	bool a; | ||||
| 	bool b; | ||||
| 	Matrix result = CreateMatrix(); | ||||
|  | ||||
| 	result.colCount = m.colCount; | ||||
| 	result.rowCount = m.rowCount; | ||||
|  | ||||
| 	for (i=0; i < m.rowCount; i++){ | ||||
| 		for (j = 0; j < m.colCount; j++){ | ||||
| 			a = GetCellValue(m, j, i); | ||||
| 			b = ErrorToFalse(GetCellValue(m, j + incrh, i + incrv)); | ||||
| 			if (XOR(a, b)){ | ||||
| 				SetCellValue(result, j, i, true); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
| Matrix leftRule(Matrix m){ | ||||
| 	Matrix result = CreateMatrix(); | ||||
| 	int i; | ||||
| 	int j; | ||||
|  | ||||
| 	result.colCount = m.colCount; | ||||
| 	result.rowCount = m.rowCount; | ||||
|  | ||||
| 	for (i=1;i<m.colCount;i++){ | ||||
| 		for (j=0;j<m.rowCount;j++){ | ||||
| 			if (GetCellValue(m, i, j)){ | ||||
| 				SetCellValue(result, i - 1, j, true); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
| Matrix rightRule(Matrix m){ | ||||
| 	Matrix result = CreateMatrix(); | ||||
| 	int i; | ||||
| 	int j; | ||||
|  | ||||
| 	result.colCount = m.colCount; | ||||
| 	result.rowCount = m.rowCount; | ||||
|  | ||||
| 	for (i=0;i<m.colCount - 1;i++){ | ||||
| 		for (j=0;j<m.rowCount;j++){ | ||||
| 			if (GetCellValue(m, i, j)){ | ||||
| 				SetCellValue(result, i + 1, j, true); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
| Matrix topRule(Matrix m){ | ||||
| 	Matrix result = CreateMatrix(); | ||||
| 	int i; | ||||
| 	int j; | ||||
|  | ||||
| 	result.colCount = m.colCount; | ||||
| 	result.rowCount = m.rowCount; | ||||
|  | ||||
| 	for (i=1;i<m.rowCount;i++){ | ||||
| 		for (j=0;j<m.colCount;j++){ | ||||
| 			if (GetCellValue(m, j, i)){ | ||||
| 				SetCellValue(result, j, i - 1, true); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
| Matrix downRule(Matrix m){ | ||||
| 	Matrix result = CreateMatrix(); | ||||
| 	int i; | ||||
| 	int j; | ||||
|  | ||||
| 	result.colCount = m.colCount; | ||||
| 	result.rowCount = m.rowCount; | ||||
|  | ||||
| 	for (i=0;i<m.rowCount - 1;i++){ | ||||
| 		for (j=0;j<m.colCount;j++){ | ||||
| 			if (GetCellValue(m, j, i)){ | ||||
| 				SetCellValue(result, j, i + 1, true); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return result; | ||||
| } | ||||
|  | ||||
| /* todos : | ||||
| *mulMatrix | ||||
| * | ||||
|   | ||||
| @@ -230,6 +230,43 @@ Matrix andRowSequenceOnMatrix(Matrix m); | ||||
| * @return matrix the copmuted matrix | ||||
| */ | ||||
| Matrix orRowSequenceOnMatrix(Matrix m); | ||||
|  | ||||
| /** | ||||
| * Apply XOR on a whole matrix | ||||
| * @param m a matrix | ||||
| * @param incrh the horizontal increment | ||||
| * @param incrv the vertical increment | ||||
| * @return matrix a new modified matrix | ||||
| */ | ||||
| Matrix basicRule(Matrix m, int incrh, int incrv); | ||||
|  | ||||
| /** | ||||
| * Apply right rule on a matrix | ||||
| * @param m a matrix | ||||
| * @return matrix a new matrix | ||||
| */ | ||||
| Matrix rightRule(Matrix m); | ||||
|  | ||||
| /** | ||||
| * Apply left rule on a matrix | ||||
| * @param m a matrix | ||||
| * @return matrix a new matrix | ||||
| */ | ||||
| Matrix leftRule(Matrix m); | ||||
| /** | ||||
| * Apply top rule on a matrix | ||||
| * @param m a matrix | ||||
| * @return matrix a new matrix | ||||
| */ | ||||
| Matrix topRule(Matrix m); | ||||
|  | ||||
| /** | ||||
| * Apply down rule on a matrix | ||||
| * @param m a matrix | ||||
| * @return matrix a new matrix | ||||
| */ | ||||
| Matrix downRule(Matrix m); | ||||
|  | ||||
| Matrix sumMatrix(Matrix matrix1,Matrix matrix2); | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user