]> Pileus Git - grits/blob - src/gis-tile.h
12d397d66cc6d3697f71bf8e8b385d441a5ee663
[grits] / src / gis-tile.h
1 /*
2  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
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 <config.h>
22 #include <glib.h>
23
24 typedef struct _GisTile        GisTile;
25
26 #define gis_tile_foreach(tile, child) \
27         for (int _x = 0; _x < G_N_ELEMENTS(tile->children); _x++) \
28         for (int _y = 0; child = tile->children[_x][_y], \
29                 _y < G_N_ELEMENTS(tile->children[_x]); _y++) \
30
31 #define gis_tile_foreach_index(tile, x, y) \
32         for (x = 0; x < G_N_ELEMENTS(tile->children); x++) \
33         for (y = 0; y < G_N_ELEMENTS(tile->children[x]); y++)
34
35 typedef void (*GisTileLoadFunc)(GisTile *tile, gpointer user_data);
36 typedef void (*GisTileFreeFunc)(GisTile *tile, gpointer user_data);
37
38 struct _GisTile {
39         /* Pointer to the tile data */
40         gpointer data;
41
42         /* North,South,East,West limits */
43         struct {
44                 gdouble n,s,e,w;
45         } edge;
46
47         /* Pointers to parent/child nodes */
48         GisTile *parent;
49         GisTile *children[2][2];
50 };
51
52 /* Path to string table, keep in sync with tile->children */ 
53 extern gchar *gis_tile_path_table[2][2];
54
55 /* Allocate a new Tile */
56 GisTile *gis_tile_new(GisTile *parent,
57         gdouble n, gdouble s, gdouble e, gdouble w);
58
59 /* Return a string representation of the tile's path */
60 gchar *gis_tile_get_path(GisTile *child);
61
62 /* Free a tile and all it's children */
63 void gis_tile_free(GisTile *root,
64                 GisTileFreeFunc free_func, gpointer user_data);
65
66 #endif