yakra / tmtools

Tools to aid in development of the TravelMapping project
0 stars 0 forks source link

canvas: rendering fails when panning: N/S poles "within" viewport #61

Closed yakra closed 6 years ago

yakra commented 6 years ago

I forget why I asked myself this, but it was to more fully understand... something.

What was holding back vertical panning? What finally enabled it?

function PanBounds(e)
{   NewLat = amerc((canvas.height-e.clientY-1)/ScaleFac+MinMerc);
    NewLon = e.clientX/ScaleFac+MinLon;
    MinLat = NewLat - LatSpan/2;
    MaxLat = NewLat + LatSpan/2;
    MinLon = NewLon - LonSpan/2;
    MaxLon = NewLon + LonSpan/2;
    ShowBounds();
    ScaleFac = Math.min((canvas.width-1)/(MaxLon-MinLon), (canvas.height-1)/(merc(MaxLat)-merc(MinLat)));
    MinMerc = merc(MinLat);
}

...was initially missing the last two lines of code.

The obvious problem that needs to be fixed here is that this just keeps the same LatSpan, in number of degrees, from the new "center" point, without accounting for Mercator projection. Need to get an actual Y value, find +/- canvas.height/4, and convert back to latitude. ToDo: implement XToLon, YToLat, LonToX, LatToY functions.

How do I even observe this bug?

The formulas that do the lat/lon<->x/y conversion are blind to the fact that we're limited to +/- 90°. Arctan should not be a problem; it's a continuous function with asymptotes of +/- pi/2. Tan? Sure, it can have values of +/- infinity, but the probability that I'm (consistently) trying to compute the tangent of exactly +/- 90° (+/- however many multiples of 180°) is vanishingly small. And I can't imagine Javascript won't let me compute tan(something >90), `cuz well, that's just not how tan works. There's something else going on here. I COULD just go and fix the damn bug. That's easy. But I want to dig deeper, and see how exactly things are getting broken...

yakra commented 6 years ago

Doy. That was blindingly easy: Can't take the natural logarithm of a negative number, hence the NaN. At least I can get on with fixing things now.