public static int[] GetRuleOrderArray(NeighborhoodOrder orderEnum) { switch (orderEnum) { case NeighborhoodOrder.Moore: case NeighborhoodOrder.MooreRuleTree: return(RuleTreeMoore); case NeighborhoodOrder.MooreRuleTable: return(RuleTableMoore); case NeighborhoodOrder.VonNeumann: case NeighborhoodOrder.VonNeumannRuleTree: return(RuleTreeVonNeumann); case NeighborhoodOrder.VonNeumannRuleTable: return(RuleTableVonNeumann); default: throw new NotImplementedException(); } }
public static IEnumerable <Point> GetAdjacentPointsToroid(this Point centerPoint, PieceGrid grid, NeighborhoodOrder neighborhoodOrder) { int[] order = GetRuleOrderArray(neighborhoodOrder); Point next; for (int i = 0; i < order.Length; i++) { next = centerPoint; next.Add(AdjacentPointDeltas[order[i]]); if (grid.IsOutOfBounds(next)) { if (next.X < 0) { next.X = grid.Size - 1; } if (next.Y < 0) { next.Y = grid.Size - 1; } if (next.X > grid.Size - 1) { next.X = 0; } if (next.Y > grid.Size - 1) { next.Y = 0; } } yield return(next); } }
public static IEnumerable <Point> GetAdjacentPointsNotOutOfBounds(this Point centerPoint, PieceGrid grid, NeighborhoodOrder neighborhoodOrder) { int[] order = GetRuleOrderArray(neighborhoodOrder); Point next; for (int i = 0; i < order.Length; i++) { next = centerPoint; next.Add(AdjacentPointDeltas[order[i]]); if (grid.IsOutOfBounds(next)) { continue; } yield return(next); } }