+static VALUE iterate_tiles_for_area(VALUE self, VALUE minlat, VALUE minlon, VALUE maxlat, VALUE maxlon)
+{
+ unsigned int minx = lon2x(NUM2DBL(minlon));
+ unsigned int maxx = lon2x(NUM2DBL(maxlon));
+ unsigned int miny = lat2y(NUM2DBL(minlat));
+ unsigned int maxy = lat2y(NUM2DBL(maxlat));
+ 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;
+}
+