+static VALUE iterate_tiles_for_area(VALUE self, VALUE bbox)
+{
+ unsigned int minx = lon2x(NUM2DBL(rb_iv_get(bbox, "@min_lon")));
+ unsigned int maxx = lon2x(NUM2DBL(rb_iv_get(bbox, "@max_lon")));
+ unsigned int miny = lat2y(NUM2DBL(rb_iv_get(bbox, "@min_lat")));
+ unsigned int maxy = lat2y(NUM2DBL(rb_iv_get(bbox, "@max_lat")));
+ tilelist_t tl = tilelist_for_area(minx, miny, maxx, maxy);
+
+ if (tl.tilec > 0)
+ {
+ unsigned int first;
+ unsigned int last;
+ unsigned int t;
+ VALUE a = rb_ary_new();
+
+ qsort(tl.tilev, tl.tilec, sizeof(unsigned int), tile_compare);
+
+ first = last = tl.tilev[0];
+
+ for (t = 1; t < tl.tilec; t++)
+ {
+ unsigned int tile = tl.tilev[t];
+
+ if (tile == last + 1)
+ {
+ last = tile;
+ }
+ else
+ {
+ rb_ary_store(a, 0, UINT2NUM(first));
+ rb_ary_store(a, 1, UINT2NUM(last));
+ rb_yield(a);
+
+ first = last = tile;
+ }
+ }
+
+ rb_ary_store(a, 0, UINT2NUM(first));
+ rb_ary_store(a, 1, UINT2NUM(last));
+ rb_yield(a);
+ }
+
+ free(tl.tilev);
+
+ return Qnil;
+}
+