protected HashSet <int[]> GetArea(int[,] mask, int xpos, int ypos, out int[] borders, Func <int, int, bool> op, int valueToFind = 1, int stopSize = 50) { HashSet <int[]> ignore = new HashSet <int[]>(); //Loop and find value, trace all connected values and store them borders = new int[4] { int.MaxValue, int.MaxValue, 0, 0 }; if (mask[xpos, ypos] == valueToFind) { //begin traversal HashSet <int[]> toCheck = new HashSet <int[]>(); toCheck.Add(new int[] { xpos, ypos }); while (toCheck.Count > 0) { var newPoints = GetSurroundingPoints(mask, ignore, toCheck.Last(), (x, y) => x == y, valueToFind); int[] last = toCheck.Last(); ignore.Add(last); borders = AdjustBorders(borders, last[0], last[1]); toCheck.Remove(last); toCheck.AddElementsUnique(newPoints); } } return(ignore); }
protected void NeatenHeights(ref int[,] geog, int maxSize, int[] bounds, MagickImage map, string thread) { HashSet <int[]> ignore = new HashSet <int[]>(); for (int x = bounds[0]; x < bounds[2]; x++) { for (int y = bounds[1]; y < bounds[3]; y++) { int[] vec = new int[] { x, y }; if (!ignore.ContainsItem(vec) && geog[x, y] < sealevel) //GetSurroundingPoints(geog, new HashSet<int[]>(), vec, (s,d) => x >= y, 1).Count > 2) { int[] borders; var area = GetArea(geog, x, y, out borders, (a, b) => a <= b, 0, maxSize); if (area.Count < maxSize + 1 && area.Count > 0) { foreach (var p in area) { int s = geog[p[0], p[1]]; geog[p[0], p[1]] = 1; } } ignore.AddElementsUnique(area); DrawPixels(map, area, geog); } } } Console.WriteLine("Thread: {0} - exiting", thread); return; }