]> Pileus Git - grits/blob - src/objects/gis-tile.h
698c0c42952d518e413bae1a397fa004fe6cc697
[grits] / src / objects / 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 #include <glib-object.h>
23 #include "gis-object.h"
24
25 #define GIS_TYPE_TILE (gis_tile_get_type())
26
27 GOBJECT_HEAD(
28         GIS, TILE,
29         Gis, Tile,
30         gis, tile);
31
32 struct _GisTile {
33         GisObject  parent_instance;
34
35         /* Pointer to the tile data */
36         gpointer data;
37
38         /* North,South,East,West limits */
39         struct {
40                 gdouble n,s,e,w;
41         } edge;
42
43         /* Pointers to parent/child nodes */
44         GisTile *parent;
45         GisTile *children[2][2];
46
47         /* Last access time (for garbage collection) */
48         time_t atime;
49 };
50
51 struct _GisTileClass {
52         GisObjectClass parent_class;
53 };
54
55 typedef void (*GisTileLoadFunc)(GisTile *tile, gpointer user_data);
56 typedef void (*GisTileFreeFunc)(GisTile *tile, gpointer user_data);
57
58 /* Forech functions */
59 #define gis_tile_foreach(tile, child) \
60         for (int _x = 0; _x < G_N_ELEMENTS(tile->children); _x++) \
61         for (int _y = 0; child = tile->children[_x][_y], \
62                 _y < G_N_ELEMENTS(tile->children[_x]); _y++) \
63
64 #define gis_tile_foreach_index(tile, x, y) \
65         for (x = 0; x < G_N_ELEMENTS(tile->children); x++) \
66         for (y = 0; y < G_N_ELEMENTS(tile->children[x]); y++)
67
68 /* Path to string table, keep in sync with tile->children */
69 extern gchar *gis_tile_path_table[2][2];
70
71 /* Allocate a new Tile */
72 GisTile *gis_tile_new(GisTile *parent,
73         gdouble n, gdouble s, gdouble e, gdouble w);
74
75 /* Return a string representation of the tile's path */
76 gchar *gis_tile_get_path(GisTile *child);
77
78 /* Update a root tile */
79 /* Based on eye distance (lat,lon,elev) */
80 void gis_tile_update(GisTile *root,
81                 gdouble res, gint width, gint height,
82                 gdouble lat, gdouble lon, gdouble elev,
83                 GisTileLoadFunc load_func, gpointer user_data);
84
85 /* Find the leaf tile containing lat-lon */
86 GisTile *gis_tile_find(GisTile *root, gdouble lat, gdouble lon);
87
88 /* Delete nodes that haven't been accessed since atime */
89 GisTile *gis_tile_gc(GisTile *root, time_t atime,
90                 GisTileFreeFunc free_func, gpointer user_data);
91
92 /* Free a tile and all it's children */
93 void gis_tile_free(GisTile *root,
94                 GisTileFreeFunc free_func, gpointer user_data);
95
96 #endif