I'm trying to figure out what's the fastest way to retrieve all the points/coordinates that are surrounding a given coordinate within a certain range in a 2D array.
I'm currently looping through the X/Y and adding all the points to a list but it turns out to be very slow when the range starts getting increased. Is there any other way of achieving this more efficiently than how I'm currently doing it?
My current code:
public static List<coords> GetCoordinates(coords Position, int nRange)
{
List<coords> inRange = new List<coords>();
for (int i = Position.X - nRange; i <= Position.X + nRange; i++)
for (int j = Position.Y - nRange; j <= Position.Y + nRange; j++)
inRange.Add(new coords() { X = i, Y = j });
return inRange;
}