]> Pileus Git - grits/blob - src/gis-tile.h
Update copyright and email address
[grits] / src / gis-tile.h
1 /*
2  * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 #ifndef __GIS_TILE_H__
19 #define __GIS_TILE_H__
20
21 #include <glib.h>
22
23 typedef struct _GisTile        GisTile;
24
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++) \
29
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++)
33
34 typedef void (*GisTileLoadFunc)(GisTile *tile, gpointer user_data);
35 typedef void (*GisTileFreeFunc)(GisTile *tile, gpointer user_data);
36
37 struct _GisTile {
38         /* Pointer to the tile data */
39         gpointer data;
40
41         /* North,South,East,West limits */
42         struct {
43                 gdouble n,s,e,w;
44         } edge;
45
46         /* Pointers to parent/child nodes */
47         GisTile *parent;
48         GisTile *children[2][2];
49
50         /* Last access time (for garbage collection) */
51         time_t atime;
52 };
53
54 /* Path to string table, keep in sync with tile->children */ 
55 extern gchar *gis_tile_path_table[2][2];
56
57 /* Allocate a new Tile */
58 GisTile *gis_tile_new(GisTile *parent,
59         gdouble n, gdouble s, gdouble e, gdouble w);
60
61 /* Return a string representation of the tile's path */
62 gchar *gis_tile_get_path(GisTile *child);
63
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);
70
71 /* Find the leaf tile containing lat-lon */
72 GisTile *gis_tile_find(GisTile *root, gdouble lat, gdouble lon);
73
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);
77
78 /* Free a tile and all it's children */
79 void gis_tile_free(GisTile *root,
80                 GisTileFreeFunc free_func, gpointer user_data);
81
82 #endif