2 * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef __GIS_TILE_H__
19 #define __GIS_TILE_H__
23 typedef struct _GisTile GisTile;
25 #define gis_tile_foreach(tile, child) \
26 for (int _x = 0; _x < G_N_ELEMENTS(tile->children); _x++) \
27 for (int _y = 0; child = tile->children[_x][_y], \
28 _y < G_N_ELEMENTS(tile->children[_x]); _y++) \
30 #define gis_tile_foreach_index(tile, x, y) \
31 for (x = 0; x < G_N_ELEMENTS(tile->children); x++) \
32 for (y = 0; y < G_N_ELEMENTS(tile->children[x]); y++)
34 typedef void (*GisTileLoadFunc)(GisTile *tile, gpointer user_data);
35 typedef void (*GisTileFreeFunc)(GisTile *tile, gpointer user_data);
38 /* Pointer to the tile data */
41 /* North,South,East,West limits */
46 /* Pointers to parent/child nodes */
48 GisTile *children[2][2];
50 /* Last access time (for garbage collection) */
54 /* Path to string table, keep in sync with tile->children */
55 extern gchar *gis_tile_path_table[2][2];
57 /* Allocate a new Tile */
58 GisTile *gis_tile_new(GisTile *parent,
59 gdouble n, gdouble s, gdouble e, gdouble w);
61 /* Return a string representation of the tile's path */
62 gchar *gis_tile_get_path(GisTile *child);
64 /* Update a root tile */
65 /* Based on eye distance (lat,lon,elev) */
66 void gis_tile_update(GisTile *root,
67 gdouble res, gint width, gint height,
68 gdouble lat, gdouble lon, gdouble elev,
69 GisTileLoadFunc load_func, gpointer user_data);
71 /* Find the leaf tile containing lat-lon */
72 GisTile *gis_tile_find(GisTile *root, gdouble lat, gdouble lon);
74 /* Delete nodes that haven't been accessed since atime */
75 GisTile *gis_tile_gc(GisTile *root, time_t atime,
76 GisTileFreeFunc free_func, gpointer user_data);
78 /* Free a tile and all it's children */
79 void gis_tile_free(GisTile *root,
80 GisTileFreeFunc free_func, gpointer user_data);