[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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -703,7 +703,7 @@ double QMapboxGL::scale() const
|
||||
|
||||
void QMapboxGL::setScale(double scale_, const QPointF ¢er)
|
||||
{
|
||||
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 ¢er) {
|
||||
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() });
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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); });
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user