/// <summary> /// Fills result list with points belonging to the component /// </summary> private static void TraverseConnectedComponentDFS(List <Vector> result, Bitmap map, Bitmap visited, int x, int y, int threshold) { if (x < 0 || x >= map.Width || y < 0 || y >= map.Height || IsVisited(visited, x, y) || !BitmapUtils.IsBelowThreshold(map, x, y, threshold)) { return; } result.Add(new Vector(x, y)); if (result.Count > 2000) { throw new MarkersNotFoundException("Couldn't traverse one of the markers: for some reason it is too large."); } visited.SetPixel(x, y, Color.Red); TraverseConnectedComponentDFS(result, map, visited, x + 1, y, threshold); TraverseConnectedComponentDFS(result, map, visited, x, y + 1, threshold); TraverseConnectedComponentDFS(result, map, visited, x - 1, y, threshold); TraverseConnectedComponentDFS(result, map, visited, x, y - 1, threshold); }