]> Pileus Git - grits/blobdiff - src/gis-tile.c
Fix misc bugs and bump version to 0.3
[grits] / src / gis-tile.c
index 80772e67909d106786f6a6a79267f79d49c76884..07baa09d6b4ab12e3f8b1a4d0bf070291a691810 100644 (file)
@@ -22,8 +22,8 @@
 #include "gis-tile.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,28 @@ 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 (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)
 {