]> Pileus Git - grits/blobdiff - src/gis-tile.c
Update copyright and email address
[grits] / src / gis-tile.c
index 80772e67909d106786f6a6a79267f79d49c76884..d92f7b5adac78280ddad75e8be2a1a3ebaca530e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
+ * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #include <config.h>
 #include <glib.h>
 
-#include "gis-world.h"
 #include "gis-tile.h"
+#include "gis-util.h"
 
 gchar *gis_tile_path_table[2][2] = {
-       {".00", ".01"},
-       {".10", ".11"},
+       {"00.", "01."},
+       {"10.", "11."},
 };
 
 GisTile *gis_tile_new(GisTile *parent,
@@ -128,6 +128,35 @@ void gis_tile_update(GisTile *self,
        }
 }
 
+GisTile *gis_tile_find(GisTile *self, gdouble lat, gdouble lon)
+{
+       gint    rows = G_N_ELEMENTS(self->children);
+       gint    cols = G_N_ELEMENTS(self->children[0]);
+
+       gdouble lat_step = (self->edge.n - self->edge.s) / rows;
+       gdouble lon_step = (self->edge.e - self->edge.w) / cols;
+
+       gdouble lat_offset = self->edge.n - lat;;
+       gdouble lon_offset = lon - self->edge.w;
+
+       gint    row = lat_offset / lat_step;
+       gint    col = lon_offset / lon_step;
+
+       if (lon == 180) col--;
+       if (lat == -90) row--;
+
+       //if (lon == 180 || lon == -180)
+       //      g_message("lat=%f,lon=%f step=%f,%f off=%f,%f row=%d/%d,col=%d/%d",
+       //              lat,lon, lat_step,lon_step, lat_offset,lon_offset, row,rows,col,cols);
+
+       if (row < 0 || row >= rows || col < 0 || col >= cols)
+               return NULL;
+       else if (self->children[row][col] && self->children[row][col]->data)
+               return gis_tile_find(self->children[row][col], lat, lon);
+       else
+               return self;
+}
+
 GisTile *gis_tile_gc(GisTile *self, time_t atime,
                GisTileFreeFunc free_func, gpointer user_data)
 {