Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Tile(x=0, y=0, z=0)
"""
tile = _parse_tile_arg(*tile)
# zoom is a keyword-only argument.
zoom = kwargs.get("zoom", None)
if zoom is not None and (tile[2] < zoom or zoom != int(zoom)):
raise InvalidZoomError(
"zoom must be an integer and less than that of the input tile"
)
x, y, z = tile
if x != int(x) or y != int(y) or z != int(z):
raise ParentTileError("the parent of a non-integer tile is undefined")
target_zoom = z - 1 if zoom is None else zoom
# Algorithm heavily inspired by https://github.com/mapbox/tilebelt.
return_tile = tile
while return_tile[2] > target_zoom:
xtile, ytile, ztile = return_tile
if xtile % 2 == 0 and ytile % 2 == 0:
return_tile = Tile(xtile // 2, ytile // 2, ztile - 1)
elif xtile % 2 == 0:
return_tile = Tile(xtile // 2, (ytile - 1) // 2, ztile - 1)
elif not xtile % 2 == 0 and ytile % 2 == 0:
return_tile = Tile((xtile - 1) // 2, ytile // 2, ztile - 1)
else:
return_tile = Tile((xtile - 1) // 2, (ytile - 1) // 2, ztile - 1)
return return_tile