public void AddNeighbours(PatternNeighbours neighbours) { foreach (var item in neighbours.directionNeighbourPatternDictionary) { if (directionNeighbourPatternDictionary.ContainsKey(item.Key) == false) { directionNeighbourPatternDictionary.Add(item.Key, new HashSet <int>()); } directionNeighbourPatternDictionary[item.Key].UnionWith(item.Value); } }
private static void FindNeighboursForEachPattern(PatternDataResults patterndataResults, Dictionary <int, PatternNeighbours> result) { for (int y = 0; y < patterndataResults.GetGridLengthInY(); y++) { for (int x = 0; x < patterndataResults.GetGridLengthInX(); x++) { PatternNeighbours neighbours = PatternFinder.CheckNeighboursInEachDirection(x, y, patterndataResults); PatternFinder.AddNeighboursToDictionary(result, patterndataResults.GetIndexAt(x, y), neighbours); } } }
public static PatternNeighbours CheckNeighboursInEachDirection(int x, int y, PatternDataResults patterndataResults) { PatternNeighbours neighbours = new PatternNeighbours(); foreach (Direction dir in Enum.GetValues(typeof(Direction))) { int possiblePatternIndex = patterndataResults.GetNeighbourInDirection(x, y, dir); if (possiblePatternIndex >= 0) { neighbours.AddPatternToDirection(dir, possiblePatternIndex); } } return(neighbours); }
public static void AddNeighboursToDictionary(Dictionary <int, PatternNeighbours> dictionary, int patternIndex, PatternNeighbours neighbours) { if (dictionary.ContainsKey(patternIndex) == false) { dictionary.Add(patternIndex, neighbours); } dictionary[patternIndex].AddNeighbours(neighbours); }