[core] Moved util::log2 to its own header
- Added util::{MIN,MAX}_ZOOM_F to avoid consecutive conversions from
double to float
- Move util::log2 to its own header (part of mbgl/math)
This commit is contained in:
@@ -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
|
||||
|
||||
27
include/mbgl/math/log2.hpp
Normal file
27
include/mbgl/math/log2.hpp
Normal file
@@ -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
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user