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