private static bool RowPatternsMatch(string[] rows, int index1, int index2) { DotRow row1 = RowPattern(rows[index1]); DotRow row2 = RowPattern(rows[index2]); bool rowPatternsMatch = true; if (row1.Count() != row2.Count()) { return(false); } for (int i = 0; i < row1.Count(); i++) { if (row1[i].simbol != row2[i].simbol) { return(false); } } for (int i = 0; i < row1.Count(); i++) { if (Math.Abs(row1[i].count - row2[i].count) > 2) { return(false); } } return(rowPatternsMatch); }
private static DotRow RowPattern(string row) { DotRow rowPattern = new DotRow(); rowPattern.Add(new Dot(row[0], 1)); for (int i = 1; i < row.Length; i++) { if (row[i] == row[i - 1]) { // increase the count if the simbol is the same Dot tmp = rowPattern[rowPattern.Count() - 1]; tmp.count++; rowPattern[rowPattern.Count() - 1] = tmp; } else { Dot newPattern = new Dot(row[i], 1); rowPattern.Add(newPattern); } } return(rowPattern); }
static void Main() { // original picture and scale int scaler1 = 4; string pic1 = @" ....************.... ...*............*... ..*..............*.. .*................*. ******************** .*................*. ..*..............*.. ...*............*... ....*..........*.... .....*........*..... ......*......*...... .......*....*....... ........*..*........ .........**......... "; int scaler2 = 7; string pic2 = @" .......*********************....... ......*.....................*...... .....*.......................*..... ....*.........................*.... ...*...........................*... ..*.............................*.. .*...............................*. *********************************** .*...............................*. ..*.............................*.. ...*...........................*... ....*.........................*.... .....*.......................*..... ......*.....................*...... .......*...................*....... ........*.................*........ .........*...............*......... ..........*.............*.......... ...........*...........*........... ............*.........*............ .............*.......*............. ..............*.....*.............. ...............*****............... "; //To Do.. // for compressed dynamic rows dwraw rows While(d0Size > or < count) "count" of dots on the LAS ROW that is the SAME NUMBER on DIFFERENT SCALERS // when checking patterns: if the dot is in the middle of the row allow 2X deviation, to allow for left and right deviation => (dotNew - dotOld<=4) OR dont check deviation ? // split pic on string rows string[] picture1 = pic1.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries); string[] picture2 = pic2.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries); DotRow dr = new DotRow(); // record the first row and iterate from second, comparing each row pattern with the previous row pattern List <DotRow> rows1 = new List <DotRow>(); rows1.Add(RowPattern(picture1[0])); for (int i = 1; i < picture1.Length; i++) { if (RowHasNewPattern(picture1, i)) { rows1.Add(RowPattern(picture1[i])); } else { rows1[rows1.Count() - 1].Count++; } } Print2(rows1); List <DotRow> rows2 = new List <DotRow>(); for (int i = 1; i < picture2.Length; i++) { if (RowHasNewPattern(picture2, i)) { rows2.Add(RowPattern(picture2[i])); } else { //RowIsDinamic(rows1, i) } } // List<ZipRow> ZippedRows = new List<ZipRow>(); // // for (int i = 0; i < rows1.Count; i++) // { // //compress row of patterns using two patterns compare and scalers // ZipRow zRowPattern = CompressRowPattern(rows1[i], rows2[i], scaler1, scaler2);// set proper scaler // ZippedRows.Add(zRowPattern); // } // // int scaler = 6; // Print(ZippedRows, scaler); }