ScanLineFillHelper.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. public class ScanLineFillHelper
  7. {
  8. public static List<int> ScaneLine(Func<int, bool> conditionFunc, List<int> edgeIndices)
  9. {
  10. List<int> fillIndices = new List<int>();
  11. for (int i = 0; i < (PlayAreaConstant.GRID_SIZE + 1); i++)
  12. {
  13. bool lastCondition = false;
  14. int startIndex = -1;
  15. int endIndex = -1;
  16. for (int j = 0; j < (PlayAreaConstant.GRID_SIZE + 1); j++)
  17. {
  18. int index = i * (PlayAreaConstant.GRID_SIZE + 1) + j;
  19. //表示找到起点
  20. if (!conditionFunc(index) && lastCondition)
  21. {
  22. if (!edgeIndices.Contains(index - 1))
  23. {
  24. startIndex = index;
  25. }
  26. }
  27. //表示找到终点
  28. if (conditionFunc(index) && !lastCondition)
  29. {
  30. if (startIndex != -1)
  31. {
  32. endIndex = index;
  33. for (int k = startIndex; k < endIndex; k++)
  34. {
  35. fillIndices.Add(k);
  36. }
  37. startIndex = -1;
  38. }
  39. }
  40. lastCondition = conditionFunc(index);
  41. }
  42. }
  43. return fillIndices;
  44. }
  45. }