Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix for #2094 - unwanted zoom changes As described in #2094 panning the map can result in a sudden jump in zoom-level as the drag is released. This jump tends to be worse when more zoomed out, and repeated short pans cause the zoom jumps to happen repeatedly in the same direction, which will grow exponentially if each one is zooming out - each zoom out causes the bug to get worse. The problem lies in recalculateZoom, which tries to calculate a new zoom level such that the previous camera altitude + terrain elevation is the same as the current camera altitude + terrain elevation. Camera altitude here refers specifically to the camera's height above the terrain elevation, and terrain elevation is the terrain height at the centre of the screen. (This doesn't really leave any good nouns for describing the sum of these two variables, but this sum should remain constant and is the camera's total height above sea level). A specific zoom maps - more-or-less - to a specific camera altitude. Since the terrain elevation can be different (eg 100m higher) at the end of a terrain drag, we need the camera altitude to be different too (eg 100m lower to compensate). So, we need to recalculate the zoom to one that maps to the required camera altitude. And so, the function recalculateZoom exists to fulfil this purpose. Unfortunately, the function miscalculates the required zoom, as can be verified by comparing camera altitude + terrain elevation before recalculateZoom is called vs after - very slight changes in terrain elevation (10s of metres) lead to large and unrelated changes in camera altitude (1000s of metres) when the camera is very zoomed out. Currently, the logic in recalculateZoom uses different math to the math used to calculate the camera's altitude from the current zoom. This different math may be close to correct, but, it's impossible for me to debug. In this commit I've simply replaced it with the inverse of the math used to calcualte the camera's altitude from its zoom - ie: if a zoom Z gives a camera altitude f(Z) Then, to get the camera to required altitude A, we need to set the zoom to Z = inverse-of-f(A) * Tests for fix for #2094 (unwanted zoom changes) Added asserts that camera altitude remains invariant throughout the recalculateZoom test. These new asserts fail before the fix for 2094. Moved the asserts that the zoom is a particular value to after the altitude asserts - a particular zoom is correct if and only if it results in the correct altitude, so whether the altitude assert fails is more important information to have in a failing test. Updated CHANGELOG.md --------- Co-authored-by: Harel M <[email protected]>
- Loading branch information