How about this algorithm:

Input:  rectangle R of tiles to request, x1,y1 ... x2,y2
1. Let R' be a copy of R
2. While width(R') > 1 and height(R') > 1, "deflate" R' by 1
3. request all tiles in the R'
4. While R' != R, "inflate" R' by 1 and request all tiles on the perimeter
of R'

Note that step 2 can be reduced to a calculation rather than a loop.



On Mon, Aug 5, 2013 at 7:15 PM, grondak <notifications@github.com> wrote:

> In map.js:
>
> > @@ -894,7 +891,7 @@ var Map;
> >
> >      // Initial z - leave room for lower/higher scale tiles
> >          z = 10 + this.max_scale - this.min_scale,
> > -        x, y, dx, dy, dw, dh,
> > +        x, y, dx, dy, dw, dh, quadrant, cx, cy, qx, qy, ax, ay,
>
> Cool. What is your newer style? I can keep to that.
> … <#1405168489fb0258_>
> On Sun, Aug 4, 2013 at 11:18 PM, Joshua Bell <notifications@github.com>wrote:
> In map.js: > @@ -894,7 +891,7 @@ var Map; > > // Initial z - leave room for
> lower/higher scale tiles > z = 10 + this.max_scale - this.min_scale, > - x,
> y, dx, dy, dw, dh, > + x, y, dx, dy, dw, dh, quadrant, cx, cy, qx, qy, ax,
> ay, FYI, I'm gradually moving away from this up-front style of declaring
> variables in JS. It's recommended by jslint and it matches how variables
> are actually scoped in JS (i.e. they are all scoped to the function, not
> any inner blocks) but it detracts from readability. — Reply to this email
> directly or view it on GitHub<
> https://github.com/inexorabletash/travellermap/pull/3/files#r5572027> .
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/inexorabletash/travellermap/pull/3/files#r5595374>
> .
>