From 30e7083cd02fd8f6441d463b9199cb007ec22fab Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sun, 6 Nov 2011 10:01:44 -0500 Subject: [PATCH] Tile.compute_path implemented and exhaustively tested --- overviewer_core/quadtree.py | 40 ++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/overviewer_core/quadtree.py b/overviewer_core/quadtree.py index 11c221c..ce991c5 100644 --- a/overviewer_core/quadtree.py +++ b/overviewer_core/quadtree.py @@ -642,4 +642,42 @@ class Tile(object): """Constructor that takes a col,row of a tile and computes the path. """ - raise NotImplementedError() + assert col % 2 == 0 + assert row % 4 == 0 + + xradius = 2**depth + yradius = 2*2**depth + + colbounds = [-xradius, xradius] + rowbounds = [-yradius, yradius] + + path = [] + + for level in xrange(depth): + # Strategy: Find the midpoint of this level, and determine which + # quadrant this row/col is in. Then set the bounds to that level + # and repeat + + xmid = (colbounds[1] + colbounds[0]) // 2 + ymid = (rowbounds[1] + rowbounds[0]) // 2 + + if col < xmid: + if row < ymid: + path.append(0) + colbounds[1] = xmid + rowbounds[1] = ymid + else: + path.append(2) + colbounds[1] = xmid + rowbounds[0] = ymid + else: + if row < ymid: + path.append(1) + colbounds[0] = xmid + rowbounds[1] = ymid + else: + path.append(3) + colbounds[0] = xmid + rowbounds[0] = ymid + + return cls(col, row, path)