summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-05-29 14:07:32 +0200
committerKonstantin Käfer <mail@kkaefer.com>2018-06-04 10:43:21 +0200
commitd66251234d7c0feb875b9490ca945ee9d43306c1 (patch)
tree3c661091edb98ac15a8711e93fde774a5e6e824a
parentd232a7a6f30927cb7e9107c9357bc53e2b1ae0f9 (diff)
downloadqtlocation-mapboxgl-d66251234d7c0feb875b9490ca945ee9d43306c1.tar.gz
[core] don't use floating point versions of pow/log
GLIBC 2.27 added new versioned symbols of powf and logf, while the double versions of pow and log remained stable. Prefer the double version to avoid introducing a dependency on a newer version of GLIBC than strictly necessary. See https://lists.gnu.org/archive/html/info-gnu/2018-02/msg00000.html
-rw-r--r--include/mbgl/math/log2.hpp13
-rw-r--r--include/mbgl/util/constants.hpp2
-rw-r--r--platform/glfw/glfw_view.cpp2
-rw-r--r--platform/qt/src/qmapboxgl.cpp4
-rw-r--r--src/mbgl/map/map.cpp2
-rw-r--r--src/mbgl/map/transform_state.cpp6
-rw-r--r--src/mbgl/renderer/layers/render_symbol_layer.cpp4
-rw-r--r--src/mbgl/renderer/sources/render_image_source.cpp2
-rw-r--r--src/mbgl/storage/resource.cpp4
-rw-r--r--src/mbgl/style/expression/compound_expression.cpp2
-rw-r--r--src/mbgl/text/collision_feature.cpp3
-rw-r--r--src/mbgl/util/interpolate.cpp3
-rw-r--r--src/mbgl/util/tile_coordinate.hpp2
-rw-r--r--src/mbgl/util/tile_cover.cpp2
14 files changed, 20 insertions, 31 deletions
diff --git a/include/mbgl/math/log2.hpp b/include/mbgl/math/log2.hpp
index 53d5e45545..6a1ba23ed9 100644
--- a/include/mbgl/math/log2.hpp
+++ b/include/mbgl/math/log2.hpp
@@ -2,7 +2,6 @@
#include <cmath>
#include <cstdint>
-#include <type_traits>
namespace mbgl {
namespace util {
@@ -11,17 +10,5 @@ namespace util {
// (== 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 ::log(x) / M_LN2;
-#else
- return ::log2(x);
-#endif
-}
-
} // namespace util
} // namespace mbgl
diff --git a/include/mbgl/util/constants.hpp b/include/mbgl/util/constants.hpp
index d5e55065c4..7110d9e26b 100644
--- a/include/mbgl/util/constants.hpp
+++ b/include/mbgl/util/constants.hpp
@@ -11,7 +11,7 @@ namespace mbgl {
namespace util {
-constexpr float tileSize = 512;
+constexpr double tileSize = 512;
/*
* The maximum extent of a feature that can be safely stored in the buffer.
diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp
index 362269b8e4..fcb470e114 100644
--- a/platform/glfw/glfw_view.cpp
+++ b/platform/glfw/glfw_view.cpp
@@ -442,7 +442,7 @@ void GLFWView::onScroll(GLFWwindow *window, double /*xOffset*/, double yOffset)
scale = 1.0 / scale;
}
- view->map->setZoom(view->map->getZoom() + std::log2(scale), mbgl::ScreenCoordinate { view->lastX, view->lastY });
+ view->map->setZoom(view->map->getZoom() + ::log2(scale), mbgl::ScreenCoordinate { view->lastX, view->lastY });
}
void GLFWView::onWindowResize(GLFWwindow *window, int width, int height) {
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp
index 8c3355dc09..58158c1822 100644
--- a/platform/qt/src/qmapboxgl.cpp
+++ b/platform/qt/src/qmapboxgl.cpp
@@ -703,7 +703,7 @@ double QMapboxGL::scale() const
void QMapboxGL::setScale(double scale_, const QPointF &center)
{
- d_ptr->mapObj->setZoom(mbgl::util::log2(scale_), mbgl::ScreenCoordinate { center.x(), center.y() });
+ d_ptr->mapObj->setZoom(::log2(scale_), mbgl::ScreenCoordinate { center.x(), center.y() });
}
/*!
@@ -1111,7 +1111,7 @@ void QMapboxGL::moveBy(const QPointF &offset)
can be used for implementing a pinch gesture.
*/
void QMapboxGL::scaleBy(double scale_, const QPointF &center) {
- d_ptr->mapObj->setZoom(d_ptr->mapObj->getZoom() + mbgl::util::log2(scale_), mbgl::ScreenCoordinate { center.x(), center.y() });
+ d_ptr->mapObj->setZoom(d_ptr->mapObj->getZoom() + ::log2(scale_), mbgl::ScreenCoordinate { center.x(), center.y() });
}
/*!
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index d81544eed5..ea35560e97 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -402,7 +402,7 @@ CameraOptions cameraForLatLngs(const std::vector<LatLng>& latLngs, const Transfo
scaleY -= (padding.top() + padding.bottom()) / height;
minScale = util::min(scaleX, scaleY);
}
- double zoom = transform.getZoom() + util::log2(minScale);
+ double zoom = transform.getZoom() + ::log2(minScale);
zoom = util::clamp(zoom, transform.getState().getMinZoom(), transform.getState().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 a85b251fb4..948954570f 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -270,7 +270,7 @@ double TransformState::zoomScale(double zoom) const {
}
double TransformState::scaleZoom(double s) const {
- return util::log2(s);
+ return ::log2(s);
}
ScreenCoordinate TransformState::latLngToScreenCoordinate(const LatLng& latLng) const {
@@ -280,7 +280,7 @@ ScreenCoordinate TransformState::latLngToScreenCoordinate(const LatLng& latLng)
mat4 mat = coordinatePointMatrix(getZoom());
vec4 p;
- Point<double> pt = Projection::project(latLng, scale) / double(util::tileSize);
+ Point<double> pt = Projection::project(latLng, scale) / util::tileSize;
vec4 c = {{ pt.x, pt.y, 0, 1 }};
matrix::transformMat4(p, c, mat);
return { p[0] / p[3], size.height - p[1] / p[3] };
@@ -427,7 +427,7 @@ float TransformState::maxPitchScaleFactor() const {
}
auto latLng = screenCoordinateToLatLng({ 0, static_cast<float>(getSize().height) });
mat4 mat = coordinatePointMatrix(getZoom());
- Point<double> pt = Projection::project(latLng, scale) / double(util::tileSize);
+ Point<double> pt = Projection::project(latLng, scale) / util::tileSize;
vec4 p = {{ pt.x, pt.y, 0, 1 }};
vec4 topPoint;
matrix::transformMat4(topPoint, p, mat);
diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp
index e48c0e2f92..3a3545122e 100644
--- a/src/mbgl/renderer/layers/render_symbol_layer.cpp
+++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp
@@ -234,7 +234,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
static const CollisionBoxProgram::PaintPropertyBinders paintAttributeData(properties, 0);
auto pixelRatio = tile.id.pixelsToTileUnits(1, parameters.state.getZoom());
- auto scale = std::pow(2.0f, float(parameters.state.getZoom() - tile.tile.id.overscaledZ));
+ const float scale = std::pow(2, parameters.state.getZoom() - tile.tile.id.overscaledZ);
std::array<float,2> extrudeScale =
{{
parameters.pixelsToGLUnits[0] / (pixelRatio * scale),
@@ -267,7 +267,7 @@ void RenderSymbolLayer::render(PaintParameters& parameters, RenderSource*) {
static const CollisionBoxProgram::PaintPropertyBinders paintAttributeData(properties, 0);
auto pixelRatio = tile.id.pixelsToTileUnits(1, parameters.state.getZoom());
- auto scale = std::pow(2.0f, float(parameters.state.getZoom() - tile.tile.id.overscaledZ));
+ const float scale = std::pow(2, parameters.state.getZoom() - tile.tile.id.overscaledZ);
std::array<float,2> extrudeScale =
{{
parameters.pixelsToGLUnits[0] / (pixelRatio * scale),
diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp
index dce5e40185..2ce046a7a0 100644
--- a/src/mbgl/renderer/sources/render_image_source.cpp
+++ b/src/mbgl/renderer/sources/render_image_source.cpp
@@ -139,7 +139,7 @@ void RenderImageSource::update(Immutable<style::Source::Impl> baseImpl_,
auto dx = nePoint.x - swPoint.x;
auto dy = nePoint.y - swPoint.y;
auto dMax = std::max(dx, dy);
- double zoom = std::max(0.0, std::floor(-util::log2(dMax)));
+ double zoom = std::max(0.0, std::floor(-::log2(dMax)));
// Only enable if the long side of the image is > 2 pixels. Resulting in a
// display of at least 2 x 1 px image
diff --git a/src/mbgl/storage/resource.cpp b/src/mbgl/storage/resource.cpp
index ba85f87dea..c51db44548 100644
--- a/src/mbgl/storage/resource.cpp
+++ b/src/mbgl/storage/resource.cpp
@@ -21,7 +21,7 @@ static std::string getQuadKey(int32_t x, int32_t y, int8_t z) {
}
static mapbox::geometry::point<double> getMercCoord(int32_t x, int32_t y, int8_t z) {
- double resolution = (util::M2PI * util::EARTH_RADIUS_M / 256) / std::pow(2.0f, z);
+ double resolution = (util::M2PI * util::EARTH_RADIUS_M / 256) / std::pow(2, z);
return {
x * resolution - util::M2PI * util::EARTH_RADIUS_M / 2,
y * resolution - util::M2PI * util::EARTH_RADIUS_M / 2,
@@ -30,7 +30,7 @@ static mapbox::geometry::point<double> getMercCoord(int32_t x, int32_t y, int8_t
static std::string getTileBBox(int32_t x, int32_t y, int8_t z) {
// Alter the y for the Google/OSM tile scheme.
- y = std::pow(2.0f, z) - y - 1;
+ y = std::pow(2, z) - y - 1;
auto min = getMercCoord(x * 256, y * 256, z);
auto max = getMercCoord((x + 1) * 256, (y + 1) * 256, z);
diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp
index 4226756fe4..a961de60ae 100644
--- a/src/mbgl/style/expression/compound_expression.cpp
+++ b/src/mbgl/style/expression/compound_expression.cpp
@@ -451,7 +451,7 @@ std::unordered_map<std::string, CompoundExpressionRegistry::Definition> initiali
define("sqrt", [](double x) -> Result<double> { return sqrt(x); });
define("log10", [](double x) -> Result<double> { return log10(x); });
define("ln", [](double x) -> Result<double> { return log(x); });
- define("log2", [](double x) -> Result<double> { return util::log2(x); });
+ define("log2", [](double x) -> Result<double> { return log2(x); });
define("sin", [](double x) -> Result<double> { return sin(x); });
define("cos", [](double x) -> Result<double> { return cos(x); });
define("tan", [](double x) -> Result<double> { return tan(x); });
diff --git a/src/mbgl/text/collision_feature.cpp b/src/mbgl/text/collision_feature.cpp
index 6d6f2aabc7..9c934624d4 100644
--- a/src/mbgl/text/collision_feature.cpp
+++ b/src/mbgl/text/collision_feature.cpp
@@ -1,5 +1,6 @@
#include <mbgl/text/collision_feature.hpp>
#include <mbgl/util/math.hpp>
+#include <mbgl/math/log2.hpp>
namespace mbgl {
@@ -50,7 +51,7 @@ void CollisionFeature::bboxifyLabel(const GeometryCoordinates& line, GeometryCoo
// symbol spacing will put labels very close together in a pitched map.
// To reduce the cost of adding extra collision circles, we slowly increase
// them for overscaled tiles.
- const float overscalingPaddingFactor = 1 + .4 * std::log(overscaling) / std::log(2);
+ const float overscalingPaddingFactor = 1 + .4 * ::log2(static_cast<double>(overscaling));
const int nPitchPaddingBoxes = std::floor(nBoxes * overscalingPaddingFactor / 2);
// offset the center of the first box by half a box so that the edge of the
diff --git a/src/mbgl/util/interpolate.cpp b/src/mbgl/util/interpolate.cpp
index 066fa9c462..6b5736f15f 100644
--- a/src/mbgl/util/interpolate.cpp
+++ b/src/mbgl/util/interpolate.cpp
@@ -13,7 +13,8 @@ float interpolationFactor(float base, Range<float> range, float z) {
} else if (base == 1.0f) {
return zoomProgress / zoomDiff;
} else {
- return (std::pow(base, zoomProgress) - 1) / (std::pow(base, zoomDiff) - 1);
+ return (std::pow(static_cast<double>(base), zoomProgress) - 1) /
+ (std::pow(static_cast<double>(base), zoomDiff) - 1);
}
}
diff --git a/src/mbgl/util/tile_coordinate.hpp b/src/mbgl/util/tile_coordinate.hpp
index bcd1c8444f..b6bdc5f590 100644
--- a/src/mbgl/util/tile_coordinate.hpp
+++ b/src/mbgl/util/tile_coordinate.hpp
@@ -20,7 +20,7 @@ public:
static TileCoordinate fromLatLng(double zoom, const LatLng& latLng) {
const double scale = std::pow(2.0, zoom);
- return { Projection::project(latLng, scale) / double(util::tileSize), zoom };
+ return { Projection::project(latLng, scale) / util::tileSize, zoom };
}
static TileCoordinate fromScreenCoordinate(const TransformState& state, double zoom, const ScreenCoordinate& screenCoordinate) {
diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp
index 488e6b88ce..3f39e53d40 100644
--- a/src/mbgl/util/tile_cover.cpp
+++ b/src/mbgl/util/tile_cover.cpp
@@ -130,7 +130,7 @@ std::vector<UnwrappedTileID> tileCover(const Point<double>& tl,
} // namespace
int32_t coveringZoomLevel(double zoom, style::SourceType type, uint16_t size) {
- zoom += std::log(util::tileSize / size) / std::log(2);
+ zoom += ::log2(util::tileSize / size);
if (type == style::SourceType::Raster || type == style::SourceType::Video) {
return ::round(zoom);
} else {