diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-06-06 16:11:22 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-06-06 22:19:25 +0300 |
commit | 313d9ce09c53d3d946a7150b7998f1b081612ff9 (patch) | |
tree | 241b8403b9c16fb3e1e3cd1daef3a5cf1ac707eb | |
parent | 7b8698b47a0ff5c4adaf474e47f89434f287f183 (diff) | |
download | qtlocation-mapboxgl-313d9ce09c53d3d946a7150b7998f1b081612ff9.tar.gz |
[core] log2 polyfill for ARMv5
ARMv5 doesn't have a FPU and apparently the soft code for log2()
is wrong and giving weird results. log() works, so we use a log()
based log2() implementation for ARMv5.
-rw-r--r-- | src/mbgl/map/map.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/util/math.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/util/math.hpp | 2 |
4 files changed, 15 insertions, 3 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 194a98153b..b08d3ef710 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -510,7 +510,7 @@ CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, optional scaleY -= (padding->top + padding->bottom) / height; } double minScale = ::fmin(scaleX, scaleY); - double zoom = ::log2(getScale() * minScale); + double zoom = util::log2(getScale() * minScale); zoom = util::clamp(zoom, getMinZoom(), getMaxZoom()); // Calculate the center point of a virtual bounds that is extended in all directions by padding. diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index ac8b6396c7..fab5991de8 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -222,7 +222,7 @@ double TransformState::zoomScale(double zoom) const { } double TransformState::scaleZoom(double s) const { - return ::log2(s); + return util::log2(s); } double TransformState::worldSize() const { diff --git a/src/mbgl/util/math.cpp b/src/mbgl/util/math.cpp index a524754109..0e86849ad3 100644 --- a/src/mbgl/util/math.cpp +++ b/src/mbgl/util/math.cpp @@ -21,5 +21,15 @@ uint32_t ceil_log2(uint64_t x) { return y; } +double log2(double x) { +// log2() is producing wrong results on ARMv5 binaries +// running on ARMv7+ CPUs. +#if defined(__ANDROID__) && defined(__ARM_ARCH_5TE__) + return std::log(x) / 0.6931471805599453; // log(x) / log(2) +#else + return ::log2(x); +#endif +} + } // namespace util -} // namespace mbgl
\ No newline at end of file +} // namespace mbgl diff --git a/src/mbgl/util/math.hpp b/src/mbgl/util/math.hpp index ef60f76ffe..bfedc2a421 100644 --- a/src/mbgl/util/math.hpp +++ b/src/mbgl/util/math.hpp @@ -110,5 +110,7 @@ T smoothstep(T edge0, T edge1, T x) { // (== number of bits required to store x) uint32_t ceil_log2(uint64_t x); +double log2(double x); + } // namespace util } // namespace mbgl |