[core] Moved wrapping to LatLng scope

Fixes a precision loss when converting unwrapped LatLngs.
This commit is contained in:
Bruno de Oliveira Abinader
2016-02-24 00:54:03 +02:00
parent b325df880b
commit abe3f9ce7a
4 changed files with 47 additions and 21 deletions

View File

@@ -101,7 +101,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
state.lngX(startLatLng.longitude),
state.latY(startLatLng.latitude),
};
unwrapLatLng(latLng);
latLng.unwrapForShortestPath(getLatLng());
const ScreenCoordinate endPoint = {
state.lngX(latLng.longitude),
state.latY(latLng.latitude),
@@ -184,7 +184,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
state.lngX(startLatLng.longitude),
state.latY(startLatLng.latitude),
};
unwrapLatLng(latLng);
latLng.unwrapForShortestPath(getLatLng());
const ScreenCoordinate endPoint = {
state.lngX(latLng.longitude),
state.latY(latLng.latitude),
@@ -329,19 +329,6 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
}, duration);
}
/** If a path crossing the antemeridian would be shorter, extend the final
coordinate so that interpolating between the two endpoints will cross it. */
void Transform::unwrapLatLng(LatLng& latLng) {
LatLng startLatLng = getLatLng();
if (std::abs(startLatLng.longitude) + std::abs(latLng.longitude) > util::LONGITUDE_MAX) {
if (startLatLng.longitude > 0 && latLng.longitude < 0) {
latLng.longitude += 360;
} else if (startLatLng.longitude < 0 && latLng.longitude > 0) {
latLng.longitude -= 360;
}
}
}
#pragma mark - Position
void Transform::moveBy(const ScreenCoordinate& offset, const Duration& duration) {