Skip to content

Instantly share code, notes, and snippets.

@JonRurka
Last active February 20, 2017 06:40
Show Gist options
  • Save JonRurka/e630a412e657e42d1d581d8e00ec1672 to your computer and use it in GitHub Desktop.
Save JonRurka/e630a412e657e42d1d581d8e00ec1672 to your computer and use it in GitHub Desktop.
public TileLocation[] GetTouchingTiles(float distance) {
TileLocation thisTile = GetTileLocation();
List<TileLocation> touchingTiles = new List<TileLocation>();
// +1,-1
if (Distance(new LatLng(thisTile.Latitude + 1, thisTile.Longitude)) <= distance)
touchingTiles.Add(thisTile + new TileLocation(1, -1));
// +1,0
if (Distance(new LatLng(thisTile.Latitude + 1, Longitude)) <= distance)
touchingTiles.Add(thisTile + new TileLocation(1, 0));
// +1,+1
if (Distance(new LatLng(thisTile.Latitude + 1, thisTile.Longitude + 1)) <= distance)
touchingTiles.Add(thisTile + new TileLocation(1, 1));
// 0,-1
if (Distance(new LatLng(Latitude, thisTile.Longitude)) <= distance)
touchingTiles.Add(thisTile + new TileLocation(0, -1));
// 0,0
if (Distance(new LatLng(thisTile.Latitude, thisTile.Longitude)) <= distance)
touchingTiles.Add(thisTile + new TileLocation(0, 0));
// 0,+1
if (Distance(new LatLng(Latitude, thisTile.Longitude + 1)) <= distance)
touchingTiles.Add(thisTile + new TileLocation(0, 1));
// -1,-1
if (Distance(new LatLng(thisTile.Latitude, thisTile.Longitude)) <= distance)
touchingTiles.Add(thisTile + new TileLocation(-1, -1));
// -1,0
if (Distance(new LatLng(thisTile.Latitude, Longitude)) <= distance)
touchingTiles.Add(thisTile + new TileLocation(-1, 0));
// -1,+1
if (Distance(new LatLng(thisTile.Latitude, thisTile.Longitude +1)) <= distance)
touchingTiles.Add(thisTile + new TileLocation(-1, 1));
return touchingTiles.ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment