+static void _grits_tile_split_latlon(GritsTile *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)
+ tile->children[row][col] = grits_tile_new(tile,
+ tile->edge.n - lat_step*(row+0), // north
+ tile->edge.n - lat_step*(row+1), // south
+ tile->edge.w + lon_step*(col+1), // east
+ tile->edge.w + lon_step*(col+0)); // west
+}
+
+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)));
+ }
+}
+