public static List <SymbolGroup <T> > ExtractGroups <T> (T[][] symbolsMatrix, int matrixWidth, int matrixHeight) where T : IComparable <T> { List <SymbolGroup <T> > groups = new List <SymbolGroup <T> > (); List <SymbolMatrixPosition <T> > all = new List <SymbolMatrixPosition <T> > (); for (int y = 0; y < matrixHeight; y++) { for (int x = 0; x < matrixWidth; x++) { all.Add(new SymbolMatrixPosition <T> (x, y, symbolsMatrix, matrixWidth, matrixHeight)); } } while (all.Count > 0) { List <SymbolMatrixPosition <T> > found = new List <SymbolMatrixPosition <T> > (); SymbolMatrixPosition <T> current = all [0]; FindNeighbours(current, found, symbolsMatrix); for (int i = 0; i < found.Count; i++) { all.Remove(found [i]); } groups.Add(CreateSymbolGroup(current.symbol, found)); } return(groups); }
public override bool Equals(object arg0) { if (arg0 == null) { return(false); } if (!(arg0 is SymbolMatrixPosition <T>)) { return(false); } SymbolMatrixPosition <T> other = (SymbolMatrixPosition <T>)arg0; return(this == other); }
private static void FindNeighbours <T> (SymbolMatrixPosition <T> position, List <SymbolMatrixPosition <T> > found, T[][] symbolsMatrix) where T : IComparable <T> { found.Add(position); foreach (SymbolMatrixDirection direction in ALL_DIRECTIONS) { SymbolMatrixPosition <T> neighbour = position.GetNeighbour(direction); if (neighbour.outOfBounds) { continue; } if (position.symbol.CompareTo(neighbour.symbol) == 0 && !found.Contains(neighbour)) { FindNeighbours(neighbour, found, symbolsMatrix); } } }