title: Get all cells in X distance of another cell. (XY Grid)
body: <p>Currently I have a function to go through a grid and update the distance of the cell to the closest cell marked as an exit. </p>
  
  <pre><code>    foreach(var tile in TileList.Values.ToList())
      {
          tile.DistanceToExit = this.GetDistanceToExit(tile);
      }
  
      public int GetDistanceToExit(Tile wantedTile)
      {
          int closestTileDistance = int.MaxValue;
          foreach(var tmptile in TileList.Where(o=&gt;o.Value.Type== TileType.Exit))
          {
                  int dx = tmptile.Key.x - wantedTile.Location.x;
                  int dy = tmptile.Key.y - wantedTile.Location.y;
  
                  double distance = Math.Sqrt(dx*dx + dy*dy);
                  int dis = (int)Math.Round(distance, MidpointRounding.AwayFromZero);
  
                  if(dis &lt; closestTileDistance)
                  {
                      closestTileDistance = dis;
                  }
          }
          return closestTileDistance;
      }
  </code></pre>
  
  <p>The problem is this is very slow when you start getting into 100x100 size grids. </p>
  
  <p>I only need to know which cells are within X cells of an exit cell. So I was thinking I should work backwards from an exit. </p>
  
  <p>Is there an algorithm for getting all cells that are within X distance of a specified cell without having to loop though all cells as I have above?</p>