summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmake/core-files.cmake3
-rw-r--r--include/mbgl/math/log2.hpp27
-rw-r--r--include/mbgl/util/constants.hpp2
-rw-r--r--src/mbgl/algorithm/generate_clip_ids_impl.hpp2
-rw-r--r--src/mbgl/layout/symbol_layout.cpp14
-rw-r--r--src/mbgl/map/map.cpp1
-rw-r--r--src/mbgl/map/transform_state.cpp4
-rw-r--r--src/mbgl/math/log2.cpp (renamed from src/mbgl/util/math.cpp)12
-rw-r--r--src/mbgl/text/collision_tile.cpp1
-rw-r--r--src/mbgl/util/math.hpp6
10 files changed, 43 insertions, 29 deletions
diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake
index 9bab51aec8..a89c0d7f4f 100644
--- a/cmake/core-files.cmake
+++ b/cmake/core-files.cmake
@@ -119,8 +119,10 @@ set(MBGL_CORE_FILES
# math
include/mbgl/math/clamp.hpp
+ include/mbgl/math/log2.hpp
include/mbgl/math/minmax.hpp
include/mbgl/math/wrap.hpp
+ src/mbgl/math/log2.cpp
# mbgl
include/mbgl/mbgl.hpp
@@ -481,7 +483,6 @@ set(MBGL_CORE_FILES
src/mbgl/util/mat3.hpp
src/mbgl/util/mat4.cpp
src/mbgl/util/mat4.hpp
- src/mbgl/util/math.cpp
src/mbgl/util/math.hpp
src/mbgl/util/offscreen_texture.cpp
src/mbgl/util/offscreen_texture.hpp
diff --git a/include/mbgl/math/log2.hpp b/include/mbgl/math/log2.hpp
new file mode 100644
index 0000000000..8a3bc7f1c0
--- /dev/null
+++ b/include/mbgl/math/log2.hpp
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <cmath>
+#include <cstdint>
+#include <type_traits>
+
+namespace mbgl {
+namespace util {
+
+// Computes the log2(x) rounded up to the next integer.
+// (== number of bits required to store x)
+uint32_t ceil_log2(uint64_t x);
+
+template <typename T>
+typename std::enable_if_t<std::is_floating_point<T>::value, T> log2(T x)
+{
+// log2() is producing wrong results on ARMv5 binaries
+// running on ARMv7+ CPUs.
+#if defined(__ANDROID__)
+ return std::log(x) / M_LN2;
+#else
+ return std::log2(x);
+#endif
+}
+
+} // namespace util
+} // namespace mbgl
diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp
index e6e9f6e67d..85e19c2ff0 100644
--- a/include/mbgl/util/constants.hpp
+++ b/include/mbgl/util/constants.hpp
@@ -35,6 +35,8 @@ constexpr double DEGREES_MAX = 360;
constexpr double PITCH_MAX = M_PI / 3;
constexpr double MIN_ZOOM = 0.0;
constexpr double MAX_ZOOM = 25.5;
+constexpr float MIN_ZOOM_F = MIN_ZOOM;
+constexpr float MAX_ZOOM_F = MAX_ZOOM;
constexpr uint64_t DEFAULT_MAX_CACHE_SIZE = 50 * 1024 * 1024;
diff --git a/src/mbgl/algorithm/generate_clip_ids_impl.hpp b/src/mbgl/algorithm/generate_clip_ids_impl.hpp
index ff8f8d3fdf..47f7df12f9 100644
--- a/src/mbgl/algorithm/generate_clip_ids_impl.hpp
+++ b/src/mbgl/algorithm/generate_clip_ids_impl.hpp
@@ -1,7 +1,7 @@
#pragma once
#include <mbgl/algorithm/generate_clip_ids.hpp>
-#include <mbgl/util/math.hpp>
+#include <mbgl/math/log2.hpp>
#include <mbgl/platform/log.hpp>
namespace mbgl {
diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp
index 0bf152e973..06f26b8ffb 100644
--- a/src/mbgl/layout/symbol_layout.cpp
+++ b/src/mbgl/layout/symbol_layout.cpp
@@ -11,12 +11,12 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/utf.hpp>
#include <mbgl/util/token.hpp>
-#include <mbgl/util/math.hpp>
#include <mbgl/util/std.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/math/clamp.hpp>
#include <mbgl/math/minmax.hpp>
+#include <mbgl/math/log2.hpp>
#include <mbgl/platform/platform.hpp>
#include <mbgl/platform/log.hpp>
@@ -418,8 +418,7 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(CollisionTile& collisionTile)
template <typename Buffer>
void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float scale, const bool keepUpright, const style::SymbolPlacementType placement, const float placementAngle) {
-
- const float placementZoom = ::fmax(std::log(scale) / std::log(2) + zoom, 0);
+ const float placementZoom = util::max(util::log2(scale) + zoom, 0.0f);
for (const auto& symbol : symbols) {
const auto &tl = symbol.tl;
@@ -428,9 +427,8 @@ void SymbolLayout::addSymbols(Buffer &buffer, const SymbolQuads &symbols, float
const auto &br = symbol.br;
const auto &tex = symbol.tex;
- float minZoom =
- util::max(static_cast<float>(zoom + log(symbol.minScale) / log(2)), placementZoom);
- float maxZoom = util::min(static_cast<float>(zoom + log(symbol.maxScale) / log(2)), 25.0f);
+ float minZoom = util::max(zoom + util::log2(symbol.minScale), placementZoom);
+ float maxZoom = util::min(zoom + util::log2(symbol.maxScale), util::MAX_ZOOM_F);
const auto &anchorPoint = symbol.anchorPoint;
// drop upside down versions of glyphs
@@ -510,8 +508,8 @@ void SymbolLayout::addToDebugBuffers(CollisionTile& collisionTile, SymbolBucket&
bl = util::matrixMultiply(collisionTile.reverseRotationMatrix, bl);
br = util::matrixMultiply(collisionTile.reverseRotationMatrix, br);
- const float maxZoom = util::clamp(zoom + log(box.maxScale) / log(2), util::MIN_ZOOM, util::MAX_ZOOM);
- const float placementZoom = util::clamp(zoom + log(box.placementScale) / log(2), util::MIN_ZOOM, util::MAX_ZOOM);
+ const float maxZoom = util::clamp(zoom + util::log2(box.maxScale), util::MIN_ZOOM_F, util::MAX_ZOOM_F);
+ const float placementZoom = util::clamp(zoom + util::log2(box.placementScale), util::MIN_ZOOM_F, util::MAX_ZOOM_F);
collisionBox.vertices.emplace_back(anchor.x, anchor.y, tl.x, tl.y, maxZoom, placementZoom);
collisionBox.vertices.emplace_back(anchor.x, anchor.y, tr.x, tr.y, maxZoom, placementZoom);
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index c7a47abebd..3daad10061 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -24,6 +24,7 @@
#include <mbgl/util/tile_coordinate.hpp>
#include <mbgl/actor/scheduler.hpp>
#include <mbgl/platform/log.hpp>
+#include <mbgl/math/log2.hpp>
namespace mbgl {
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index 188b3aa79a..5a8d495bac 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -2,7 +2,7 @@
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/interpolate.hpp>
-#include <mbgl/util/math.hpp>
+#include <mbgl/math/log2.hpp>
#include <mbgl/math/clamp.hpp>
namespace mbgl {
@@ -117,7 +117,7 @@ double TransformState::pixel_y() const {
#pragma mark - Zoom
double TransformState::getZoom() const {
- return std::log(scale) / M_LN2;
+ return scaleZoom(scale);
}
int32_t TransformState::getIntegerZoom() const {
diff --git a/src/mbgl/util/math.cpp b/src/mbgl/math/log2.cpp
index 7b1516c041..222e67dbd7 100644
--- a/src/mbgl/util/math.cpp
+++ b/src/mbgl/math/log2.cpp
@@ -1,4 +1,4 @@
-#include <mbgl/util/math.hpp>
+#include <mbgl/math/log2.hpp>
namespace mbgl {
namespace util {
@@ -21,15 +21,5 @@ 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__)
- return std::log(x) / 0.6931471805599453; // log(x) / log(2)
-#else
- return ::log2(x);
-#endif
-}
-
} // namespace util
} // namespace mbgl
diff --git a/src/mbgl/text/collision_tile.cpp b/src/mbgl/text/collision_tile.cpp
index e485fbf36c..419ab31a79 100644
--- a/src/mbgl/text/collision_tile.cpp
+++ b/src/mbgl/text/collision_tile.cpp
@@ -1,5 +1,6 @@
#include <mbgl/text/collision_tile.hpp>
#include <mbgl/geometry/feature_index.hpp>
+#include <mbgl/math/log2.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/math.hpp>
#include <mbgl/math/minmax.hpp>
diff --git a/src/mbgl/util/math.hpp b/src/mbgl/util/math.hpp
index 5d4220d0a2..f969ecaedd 100644
--- a/src/mbgl/util/math.hpp
+++ b/src/mbgl/util/math.hpp
@@ -106,11 +106,5 @@ T smoothstep(T edge0, T edge1, T x) {
return t * t * (T(3) - T(2) * t);
}
-// Computes the log2(x) rounded up to the next integer.
-// (== number of bits required to store x)
-uint32_t ceil_log2(uint64_t x);
-
-double log2(double x);
-
} // namespace util
} // namespace mbgl