This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
Normalize angle of 360 degrees to 0 degrees - #1558
Closed
friedbunny wants to merge 1 commit into
Closed
friedbunny wants to merge 1 commit into
friedbunny wants to merge 1 commit into
Conversation
When interpolating across 180º, _normalizeAngle will return >180º. Then trying to reset the bearing to 0º would result in interpolation to 360º when we were expecting 0º. Result: iOS compass would not disappear when reset because it expects 0º.
Contributor
|
In the course of refactoring the compass for #1496, I discovered another off-by-ε error that may be related. |
Contributor
|
Does this preserve the behavior that animated rotations from ø > 180º to 0º take the shortest path around the circle, i.e. to 360º? |
Contributor
Author
Contributor
Author
|
Found an easier way to trigger the original bug: do the rotation gesture very hard. |
Member
|
Does this only happen for 180 degrees? If so, it looks like the culprit may be in |
Contributor
Author
|
Perhaps @mourner could weigh in on our use of template <typename T>
T wrap(T value, T min, T max) {
T d = max - min;
return value == max ? value : std::fmod((std::fmod((value - min), d) + d), d) + min;
}JS implementation is here. |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes the compass not disappearing after it is reset, especially when returning from the background.
When interpolating across 180º,
_normalizeAnglewill return >180º. Then, trying to reset the bearing to 0º would result in interpolation to 360º. Because[MGLMapView updateCompass]expects bearing to equal 0º when the compass is done resetting, the compass was never disappearing.Steps to reproduce
You can also test this by setting a breakpoint in
/src/mbgl/map/transform.cpp_normalizeAngleand doing this:Start by moving to 171º from 196º:
When it comes time to reset to 0º from 189º:
Which is the same as 0º, but not what we're looking for.
/cc @1ec5 @incanus