public GravityCell[,] getRadiusNeighbours(int x, int y, float circularRadius) { int a; int b; for (int i = (x - (int)circularRadius); i <= (x + (int)circularRadius); ++i) { for (int j = (y - (int)circularRadius); j <= (y + (int)circularRadius); ++j) { a = i; b = j; if (!neighbourhood.GetIsPeriodic()) { if (i < 0) { a = 0; } if (i >= neighbourhood.GetNodesPerWidth()) { a = neighbourhood.GetNodesPerWidth() - 1; } if (j < 0) { b = 0; } if (j >= neighbourhood.GetNodesPerHeight()) { b = neighbourhood.GetNodesPerHeight() - 1; } } else { if (i < 0) { a = neighbourhood.GetNodesPerWidth() + i - 1; } if (i >= neighbourhood.GetNodesPerWidth()) { a = i - neighbourhood.GetNodesPerWidth(); } if (j < 0) { b = neighbourhood.GetNodesPerHeight() + j - 1; } if (j >= neighbourhood.GetNodesPerHeight()) { b = j - neighbourhood.GetNodesPerHeight(); } } if (neighbourhood.GetIsPeriodic() && (i < 0 || i >= neighbourhood.GetNodesPerWidth())) { if (neighbourhood.GetSeedTab()[a, b].GetValue() == 0 && neighbourhood.GetSeedTabNew()[a, b].GetValue() == 0 && twoPointsDifference(neighbourhood.GetSeedTab()[a, b], neighbourhood.GetSeedTab()[x, y]) < (circularRadius * PIXEL_SIZE + neighbourhood.GetNodesPerWidth() * PIXEL_SIZE)) { neighbourhood.GetSeedTabNew()[a, b].SetValue(neighbourhood.GetSeedTab()[x, y].GetValue()); } } else if (neighbourhood.GetIsPeriodic() && (j < 0 || j >= neighbourhood.GetNodesPerHeight())) { if (neighbourhood.GetSeedTab()[a, b].GetValue() == 0 && neighbourhood.GetSeedTabNew()[a, b].GetValue() == 0 && twoPointsDifference(neighbourhood.GetSeedTab()[a, b], neighbourhood.GetSeedTab()[x, y]) < (circularRadius * PIXEL_SIZE + neighbourhood.GetNodesPerHeight() * PIXEL_SIZE)) { neighbourhood.GetSeedTabNew()[a, b].SetValue(neighbourhood.GetSeedTab()[x, y].GetValue()); } } else { if (neighbourhood.GetSeedTab()[a, b].GetValue() == 0 && neighbourhood.GetSeedTabNew()[a, b].GetValue() == 0 && twoPointsDifference(neighbourhood.GetSeedTab()[a, b], neighbourhood.GetSeedTab()[x, y]) < (circularRadius * PIXEL_SIZE)) { neighbourhood.GetSeedTabNew()[a, b].SetValue(neighbourhood.GetSeedTab()[x, y].GetValue()); } } } } return(neighbourhood.GetSeedTab()); }
public GravityCell[,] GetHexagonalNeighbours(int x, int y, int hexaCase) { int[] neighbours = new int[neighbourhood.GetGrains().Count]; for (int i = 0; i < neighbourhood.GetGrains().Count; ++i) { neighbours[i] = 0; } int[] closeNeighbours = neighbourhood.GetPeriodicIndex(x, y); int left = closeNeighbours[0]; int right = closeNeighbours[1]; int up = closeNeighbours[2]; int down = closeNeighbours[3]; switch (hexaCase) { case 0: if (neighbourhood.GetSeedTab()[x, up].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[x, up].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[right, up].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[right, up].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[right, y].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[right, y].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[left, y].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[left, y].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[left, down].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[left, down].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[x, down].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[x, down].GetValue() - 1]++; } break; case 1: if (neighbourhood.GetSeedTab()[x, up].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[x, up].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[left, up].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[left, up].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[left, y].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[left, y].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[right, y].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[right, y].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[right, down].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[right, down].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[x, down].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[x, down].GetValue() - 1]++; } break; default: break; } return(neighbourhood.GetBiggestNaighbour(neighbours, x, y)); }
public GravityCell[,] GetMooreNeighbours(int x, int y) { int[] neighbours = new int[neighbourhood.GetGrains().Count]; for (int i = 0; i < neighbourhood.GetGrains().Count; ++i) { neighbours[i] = 0; } int[] closeNeighbours = neighbourhood.GetPeriodicIndex(x, y); int left = closeNeighbours[0]; int right = closeNeighbours[1]; int up = closeNeighbours[2]; int down = closeNeighbours[3]; if (neighbourhood.GetSeedTab()[left, up].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[left, up].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[left, y].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[left, y].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[left, down].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[left, down].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[right, up].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[right, up].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[right, y].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[right, y].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[right, down].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[right, down].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[x, up].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[x, up].GetValue() - 1]++; } if (neighbourhood.GetSeedTab()[x, down].GetValue() != 0) { neighbours[neighbourhood.GetSeedTab()[x, down].GetValue() - 1]++; } return(neighbourhood.GetBiggestNaighbour(neighbours, x, y)); }