diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2018-05-29 14:07:32 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2018-06-04 10:43:21 +0200 |
commit | d66251234d7c0feb875b9490ca945ee9d43306c1 (patch) | |
tree | 3c661091edb98ac15a8711e93fde774a5e6e824a /src | |
parent | d232a7a6f30927cb7e9107c9357bc53e2b1ae0f9 (diff) | |
download | qtlocation-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
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/map.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/layers/render_symbol_layer.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_image_source.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/storage/resource.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/expression/compound_expression.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/text/collision_feature.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/util/interpolate.cpp | 3 | ||||
-rw-r--r-- | src/mbgl/util/tile_coordinate.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/util/tile_cover.cpp | 2 |
10 files changed, 16 insertions, 14 deletions
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 { |