Skip to content

Instantly share code, notes, and snippets.

@beelsebob
Created January 21, 2012 19:17
Show Gist options
  • Select an option

  • Save beelsebob/1653642 to your computer and use it in GitHub Desktop.

Select an option

Save beelsebob/1653642 to your computer and use it in GitHub Desktop.
NSArray *NSArrayOfTilesFromCoordinateRectWithinTile(OSPCoordinateRect r, double maxOverspill, OSPTile t)
{
OSPCoordinateRect tileRect = OSPCoordinateRectFromTile(t);
if (OSPCoordinateRectIntersectsRect(r, tileRect))
{
BOOL splitVertically = OSPCoordinateRectGetMinLongitude(r) - maxOverspill > OSPCoordinateRectGetMinLongitude(tileRect) || OSPCoordinateRectGetMaxLongitude(r) + maxOverspill < OSPCoordinateRectGetMaxLongitude(tileRect);
BOOL splitHorizontally = OSPCoordinateRectGetMinLatitude(r) - maxOverspill > OSPCoordinateRectGetMinLatitude(tileRect) || OSPCoordinateRectGetMaxLatitude(r) + maxOverspill < OSPCoordinateRectGetMaxLatitude(tileRect);
if (splitVertically || splitHorizontally)
{
NSArray *bottomLeft = NSArrayOfTilesFromCoordinateRectWithinTile(r, maxOverspill, (OSPTile){.x = t.x * 2 , .y = t.y * 2 , .zoom = t.zoom + 1});
NSArray *bottomRight = NSArrayOfTilesFromCoordinateRectWithinTile(r, maxOverspill, (OSPTile){.x = t.x * 2 + 1, .y = t.y * 2 , .zoom = t.zoom + 1});
NSArray *topLeft = NSArrayOfTilesFromCoordinateRectWithinTile(r, maxOverspill, (OSPTile){.x = t.x * 2 , .y = t.y * 2 + 1, .zoom = t.zoom + 1});
NSArray *topRight = NSArrayOfTilesFromCoordinateRectWithinTile(r, maxOverspill, (OSPTile){.x = t.x * 2 + 1, .y = t.y * 2 + 1, .zoom = t.zoom + 1});
return [[bottomLeft arrayByAddingObjectsFromArray:bottomRight] arrayByAddingObjectsFromArray:[topLeft arrayByAddingObjectsFromArray:topRight]];
}
else
{
return [NSArray arrayWithObject:[OSPValue valueWithTile:t]];
}
}
return [NSArray array];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment