+static void _grits_tile_split_latlon(GritsTile *tile)
+{
+ //g_debug("GritsTile: split - %p", tile);
+ const gdouble rows = G_N_ELEMENTS(tile->children);
+ const gdouble cols = G_N_ELEMENTS(tile->children[0]);
+ const gdouble lat_dist = tile->edge.n - tile->edge.s;
+ const gdouble lon_dist = tile->edge.e - tile->edge.w;
+ const gdouble lat_step = lat_dist / rows;
+ const gdouble lon_step = lon_dist / cols;
+
+ int row, col;
+ grits_tile_foreach_index(tile, row, col) {
+ if (!tile->children[row][col])
+ tile->children[row][col] =
+ grits_tile_new(tile, 0, 0, 0, 0);
+ /* Set edges aferwards so that north and south
+ * get reset for mercator projections */
+ GritsTile *child = tile->children[row][col];
+ child->edge.n = tile->edge.n - lat_step*(row+0);
+ child->edge.s = tile->edge.n - lat_step*(row+1);
+ child->edge.e = tile->edge.w + lon_step*(col+1);
+ child->edge.w = tile->edge.w + lon_step*(col+0);
+ }
+}
+
+static void _grits_tile_split_mercator(GritsTile *tile)
+{
+ GritsTile *child = NULL;
+ GritsBounds tmp = tile->edge;
+
+ /* Project */
+ tile->edge.n = asinh(tan(deg2rad(tile->edge.n)));
+ tile->edge.s = asinh(tan(deg2rad(tile->edge.s)));
+
+ _grits_tile_split_latlon(tile);
+
+ /* Convert back to lat-lon */
+ tile->edge = tmp;
+ grits_tile_foreach(tile, child) {
+ child->edge.n = rad2deg(atan(sinh(child->edge.n)));
+ child->edge.s = rad2deg(atan(sinh(child->edge.s)));
+ }
+}
+