2 * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
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__
22 #include <glib-object.h>
23 #include "gis-object.h"
25 #define GIS_TYPE_TILE (gis_tile_get_type())
26 #define GIS_TILE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GIS_TYPE_TILE, GisTile))
27 #define GIS_IS_TILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GIS_TYPE_TILE))
28 #define GIS_TILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIS_TYPE_TILE, GisTileClass))
29 #define GIS_IS_TILE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIS_TYPE_TILE))
30 #define GIS_TILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIS_TYPE_TILE, GisTileClass))
32 typedef struct _GisTile GisTile;
33 typedef struct _GisTileClass GisTileClass;
36 GisObject parent_instance;
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 struct _GisTileClass {
55 GisObjectClass parent_class;
58 typedef void (*GisTileLoadFunc)(GisTile *tile, gpointer user_data);
59 typedef void (*GisTileFreeFunc)(GisTile *tile, gpointer user_data);
61 /* Forech functions */
62 #define gis_tile_foreach(parent, child) \
63 for (int _x = 0; _x < G_N_ELEMENTS(parent->children); _x++) \
64 for (int _y = 0; child = parent->children[_x][_y], \
65 _y < G_N_ELEMENTS(parent->children[_x]); _y++)
67 #define gis_tile_foreach_index(parent, x, y) \
68 for (x = 0; x < G_N_ELEMENTS(parent->children); x++) \
69 for (y = 0; y < G_N_ELEMENTS(parent->children[x]); y++)
71 /* Path to string table, keep in sync with tile->children */
72 extern gchar *gis_tile_path_table[2][2];
74 GType gis_tile_get_type(void);
76 /* Allocate a new Tile */
77 GisTile *gis_tile_new(GisTile *parent,
78 gdouble n, gdouble s, gdouble e, gdouble w);
80 /* Return a string representation of the tile's path */
81 gchar *gis_tile_get_path(GisTile *child);
83 /* Update a root tile */
84 /* Based on eye distance (lat,lon,elev) */
85 void gis_tile_update(GisTile *root,
86 gdouble res, gint width, gint height,
87 gdouble lat, gdouble lon, gdouble elev,
88 GisTileLoadFunc load_func, gpointer user_data);
90 /* Find the leaf tile containing lat-lon */
91 GisTile *gis_tile_find(GisTile *root, gdouble lat, gdouble lon);
93 /* Delete nodes that haven't been accessed since atime */
94 GisTile *gis_tile_gc(GisTile *root, time_t atime,
95 GisTileFreeFunc free_func, gpointer user_data);
97 /* Free a tile and all it's children */
98 void gis_tile_free(GisTile *root,
99 GisTileFreeFunc free_func, gpointer user_data);