From 8382e6664a1f380f1297e86af6f3d4f9fdbb2083 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Tue, 7 Sep 2010 21:32:57 -0400 Subject: [PATCH] cleaned up some comments --- gmap.py | 3 ++- world.py | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/gmap.py b/gmap.py index 7ff6de0..a8840fe 100755 --- a/gmap.py +++ b/gmap.py @@ -42,9 +42,10 @@ def main(): os.mkdir(destdir) zoom = world.get_quadtree_depth(mincol, maxcol, minrow, maxrow) write_html(destdir, zoom+1) + print "Your map will have {0} zoom levels".format(zoom+1) print "Generating quad tree. This may take a while and has no progress bar right now, so sit tight." - tiledir = os.path.join(destdir, "tiles"); + tiledir = os.path.join(destdir, "tiles") if not os.path.exists(tiledir): os.mkdir(tiledir) world.generate_quadtree(results, mincol, maxcol, minrow, maxrow, tiledir) diff --git a/world.py b/world.py index 10a7aac..e22812d 100644 --- a/world.py +++ b/world.py @@ -295,13 +295,19 @@ def render_worldtile(chunkmap, colstart, colend, rowstart, rowend, oldhash): def get_quadtree_depth(colstart, colend, rowstart, rowend): """Determines the zoom depth of a requested quadtree. - Return value is an integer >= 0. Higher integers mean higher resolution maps. + Return value is an integer >= 0. Higher integers mean higher resolution + maps. This is one less than the maximum zoom (level 0 is a single tile, + level 1 is 2 tiles wide by 2 tiles high, etc.) + """ - # Pulled out of generate_quadtree. Original comment follows: + # This determines how many zoom levels we need to encompass the entire map. + # We need to make sure that each recursive call splits both dimensions + # evenly into a power of 2 tiles wide and high, so this function determines + # how many splits to make, and generate_quadtree() uses this to adjust the + # row and column limits so that everything splits just right. # - # This first call has a special job. No matter the input, we need to - # make sure that each recursive call splits both dimensions evenly - # into a power of 2 tiles wide and high. + # This comment makes more sense if you consider it inlined in its call from + # generate_quadtree() # Since a single tile has 3 columns of chunks and 5 rows of chunks, this # split needs to be sized into the void so that it is some number of rows # in the form 2*2^p. And columns must be in the form 4*2^p @@ -324,23 +330,20 @@ def generate_quadtree(chunkmap, colstart, colend, rowstart, rowend, prefix): """Base call for quadtree_recurse. This sets up the recursion and generates a quadtree given a chunkmap and the ranges. - This returns the power of 2 tiles wide and high the image is. This is one - less than the maximum zoom (level 0 is a single tile, level 1 is 2 tiles - wide by 2 tiles high, etc.) - """ p = get_quadtree_depth(colstart, colend, rowstart, rowend); colmid = (colstart + colend) // 2 rowmid = (rowstart + rowend) // 2 - # Modify the lower and upper bounds to be sized correctly + # Modify the lower and upper bounds to be sized correctly. See comments in + # get_quadtree_depth() colstart = colmid - 2*2**p colend = colmid + 2*2**p rowstart = rowmid - 4*2**p rowend = rowmid + 4*2**p - print " power is", p - print " new bounds: {0},{1} {2},{3}".format(colstart, colend, rowstart, rowend) + #print " power is", p + #print " new bounds: {0},{1} {2},{3}".format(colstart, colend, rowstart, rowend) quadtree_recurse(chunkmap, colstart, colend, rowstart, rowend, prefix, "base")