summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-05-14 16:40:24 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-05-14 16:40:24 +0200
commitb167a79c22ed3e65941305a7d8e0fedb796dd11f (patch)
treed18abbec96b0b12eb26d809b5b9abdc7b305c37c
parentb8d88600b81372a7544ebe420c562c4fa02592e9 (diff)
downloadqtlocation-mapboxgl-b167a79c22ed3e65941305a7d8e0fedb796dd11f.tar.gz
always use std:: namespace for math functions
fixes #201
-rw-r--r--common/glfw_view.cpp4
-rw-r--r--include/llmr/map/tile.hpp2
-rw-r--r--include/llmr/map/transform.hpp4
-rw-r--r--include/llmr/util/math.hpp10
-rw-r--r--src/csscolorparser/csscolorparser.cpp2
-rw-r--r--src/geometry/debug_font_buffer.cpp4
-rw-r--r--src/geometry/line_buffer.cpp4
-rw-r--r--src/geometry/text_buffer.cpp12
-rw-r--r--src/map/source.cpp16
-rw-r--r--src/map/tile.cpp8
-rw-r--r--src/map/transform.cpp34
-rw-r--r--src/map/transform_state.cpp14
-rw-r--r--src/renderer/fill_bucket.cpp2
-rw-r--r--src/renderer/line_bucket.cpp6
-rw-r--r--src/renderer/painter.cpp4
-rw-r--r--src/renderer/painter_fill.cpp8
-rw-r--r--src/renderer/painter_line.cpp6
-rw-r--r--src/renderer/painter_text.cpp12
-rw-r--r--src/style/properties.cpp6
-rw-r--r--src/text/collision.cpp16
-rw-r--r--src/text/placement.cpp16
-rw-r--r--src/text/rotation_range.cpp24
-rw-r--r--src/util/mat4.cpp4
-rw-r--r--test/rotation_range.cpp12
24 files changed, 115 insertions, 115 deletions
diff --git a/common/glfw_view.cpp b/common/glfw_view.cpp
index 4bdac5f6b0..7ec5d3b083 100644
--- a/common/glfw_view.cpp
+++ b/common/glfw_view.cpp
@@ -88,10 +88,10 @@ void GLFWView::scroll(GLFWwindow *window, double /*xoffset*/, double yoffset) {
GLFWView *view = (GLFWView *)glfwGetWindowUserPointer(window);
double delta = yoffset * 40;
- bool is_wheel = delta != 0 && fmod(delta, 4.000244140625) == 0;
+ bool is_wheel = delta != 0 && std::fmod(delta, 4.000244140625) == 0;
double absdelta = delta < 0 ? -delta : delta;
- double scale = 2.0 / (1.0 + exp(-absdelta / 100.0));
+ double scale = 2.0 / (1.0 + std::exp(-absdelta / 100.0));
// Make the scroll wheel a bit slower.
if (!is_wheel) {
diff --git a/include/llmr/map/tile.hpp b/include/llmr/map/tile.hpp
index 76a01e04e8..0f43f9df2b 100644
--- a/include/llmr/map/tile.hpp
+++ b/include/llmr/map/tile.hpp
@@ -33,7 +33,7 @@ public:
: w((x < 0 ? x - (1 << z) + 1 : x) / (1 << z)), z(z), x(x), y(y) {}
inline uint64_t to_uint64() const {
- return ((pow(2, z) * y + x) * 32) + z;
+ return ((std::pow(2, z) * y + x) * 32) + z;
}
inline operator std::string() const {
diff --git a/include/llmr/map/transform.hpp b/include/llmr/map/transform.hpp
index 6b43521309..472d01ab7e 100644
--- a/include/llmr/map/transform.hpp
+++ b/include/llmr/map/transform.hpp
@@ -81,8 +81,8 @@ private:
// Limit the amount of zooming possible on the map.
// TODO: make these modifiable from outside.
- const double min_scale = pow(2, 0);
- const double max_scale = pow(2, 20);
+ const double min_scale = std::pow(2, 0);
+ const double max_scale = std::pow(2, 20);
// cache values for spherical mercator math
double zc, Bc, Cc;
diff --git a/include/llmr/util/math.hpp b/include/llmr/util/math.hpp
index d356cf8763..531a13a1a5 100644
--- a/include/llmr/util/math.hpp
+++ b/include/llmr/util/math.hpp
@@ -44,7 +44,7 @@ inline T min(T a, T b, T c, T d) {
// a x b = |a||b|sin(θ) for θ.
template <typename T = double, typename S>
inline T angle_between(S ax, S ay, S bx, S by) {
- return atan2((ax * by - ay * bx), ax * bx + ay * by);
+ return std::atan2((ax * by - ay * bx), ax * bx + ay * by);
}
template <typename T = double, typename S>
@@ -54,7 +54,7 @@ inline T angle_between(const vec2<S>& a, const vec2<S>& b) {
template <typename T = double, typename S>
inline T angle_to(const vec2<S>& a, const vec2<S>& b) {
- return atan2(a.y - b.y, a.x - b.x);
+ return std::atan2(a.y - b.y, a.x - b.x);
}
template <typename T, typename S1, typename S2>
@@ -75,7 +75,7 @@ template <typename T, typename S1, typename S2>
inline vec2<T> normal(const S1& a, const S2& b) {
T dx = b.x - a.x;
T dy = b.y - a.y;
- T c = sqrt(dx * dx + dy * dy);
+ T c = std::sqrt(dx * dx + dy * dy);
return { dx / c, dy / c };
}
@@ -83,14 +83,14 @@ template <typename T, typename S1, typename S2>
inline T dist(const S1& a, const S2& b) {
T dx = b.x - a.x;
T dy = b.y - a.y;
- T c = sqrt(dx * dx + dy * dy);
+ T c = std::sqrt(dx * dx + dy * dy);
return c;
}
// Take the magnitude of vector a.
template <typename T = double, typename S>
inline T mag(const S& a) {
- return sqrt(a.x * a.x + a.y * a.y);
+ return std::sqrt(a.x * a.x + a.y * a.y);
}
}
diff --git a/src/csscolorparser/csscolorparser.cpp b/src/csscolorparser/csscolorparser.cpp
index 6ee0ba9161..d52c6280cf 100644
--- a/src/csscolorparser/csscolorparser.cpp
+++ b/src/csscolorparser/csscolorparser.cpp
@@ -114,7 +114,7 @@ const std::map<std::string, Color> kCSSColorTable = {
template <typename T>
uint8_t clamp_css_byte(T i) { // Clamp to integer 0 .. 255.
- i = round(i); // Seems to be what Chrome does (vs truncation).
+ i = std::round(i); // Seems to be what Chrome does (vs truncation).
return i < 0 ? 0 : i > 255 ? 255 : i;
}
diff --git a/src/geometry/debug_font_buffer.cpp b/src/geometry/debug_font_buffer.cpp
index a91865fb81..9febbc518d 100644
--- a/src/geometry/debug_font_buffer.cpp
+++ b/src/geometry/debug_font_buffer.cpp
@@ -31,8 +31,8 @@ void DebugFontBuffer::addText(const char *text, double left, double baseline, do
if (glyph.data[j] == -1 && glyph.data[j + 1] == -1) {
prev = false;
} else {
- int16_t x = round(left + glyph.data[j] * scale);
- int16_t y = round(baseline - glyph.data[j + 1] * scale);
+ int16_t x = std::round(left + glyph.data[j] * scale);
+ int16_t y = std::round(baseline - glyph.data[j + 1] * scale);
if (prev) {
coords = static_cast<uint16_t *>(addElement());
coords[0] = prev_x;
diff --git a/src/geometry/line_buffer.cpp b/src/geometry/line_buffer.cpp
index 736235775f..a80ded5fbe 100644
--- a/src/geometry/line_buffer.cpp
+++ b/src/geometry/line_buffer.cpp
@@ -14,8 +14,8 @@ size_t LineVertexBuffer::add(vertex_type x, vertex_type y, float ex, float ey, i
coords[1] = (y * 2) | ty;
int8_t *extrude = static_cast<int8_t *>(data);
- extrude[4] = round(extrudeScale * ex);
- extrude[5] = round(extrudeScale * ey);
+ extrude[4] = std::round(extrudeScale * ex);
+ extrude[5] = std::round(extrudeScale * ey);
coords[3] = linesofar;
diff --git a/src/geometry/text_buffer.cpp b/src/geometry/text_buffer.cpp
index d8b2eb6ef2..d3529c5604 100644
--- a/src/geometry/text_buffer.cpp
+++ b/src/geometry/text_buffer.cpp
@@ -15,21 +15,21 @@ size_t TextVertexBuffer::add(int16_t x, int16_t y, float ox, float oy, uint16_t
int16_t *shorts = static_cast<int16_t *>(data);
shorts[0] = x;
shorts[1] = y;
- shorts[2] = round(ox * 64); // use 1/64 pixels for placement
- shorts[3] = round(oy * 64);
+ shorts[2] = std::round(ox * 64); // use 1/64 pixels for placement
+ shorts[3] = std::round(oy * 64);
uint8_t *ubytes = static_cast<uint8_t *>(data);
// a_data1
ubytes[8] = tx / 4;
ubytes[9] = ty / 4;
ubytes[10] = labelminzoom * 10;
- ubytes[11] = (int16_t)round(angle * angleFactor) % 256;
+ ubytes[11] = (int16_t)std::round(angle * angleFactor) % 256;
// a_data2
ubytes[12] = minzoom * 10; // 1/10 zoom levels: z16 == 160.
- ubytes[13] = fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160.
- ubytes[14] = util::max((int16_t)round(range[0] * angleFactor), (int16_t)0) % 256;
- ubytes[15] = util::min((int16_t)round(range[1] * angleFactor), (int16_t)255) % 256;
+ ubytes[13] = std::fmin(maxzoom, 25) * 10; // 1/10 zoom levels: z16 == 160.
+ ubytes[14] = util::max((int16_t)std::round(range[0] * angleFactor), (int16_t)0) % 256;
+ ubytes[15] = util::min((int16_t)std::round(range[1] * angleFactor), (int16_t)255) % 256;
return idx;
}
diff --git a/src/map/source.cpp b/src/map/source.cpp
index a5985668fc..91ccdbc9cc 100644
--- a/src/map/source.cpp
+++ b/src/map/source.cpp
@@ -312,8 +312,8 @@ edge _edge(const llmr::vec2<double> a, const llmr::vec2<double> b) {
// scan-line conversion
void _scanSpans(edge e0, edge e1, int32_t ymin, int32_t ymax, ScanLine scanLine) {
- double y0 = fmax(ymin, floor(e1.y0)),
- y1 = fmin(ymax, ceil(e1.y1));
+ double y0 = std::fmax(ymin, std::floor(e1.y0)),
+ y1 = std::fmin(ymax, std::ceil(e1.y1));
// sort edges by x-coordinate
if ((e0.x0 == e1.x0 && e0.y0 == e1.y0) ?
@@ -328,9 +328,9 @@ void _scanSpans(edge e0, edge e1, int32_t ymin, int32_t ymax, ScanLine scanLine)
d0 = e0.dx > 0, // use y + 1 to compute x0
d1 = e1.dx < 0; // use y + 1 to compute x1
for (int32_t y = y0; y < y1; y++) {
- double x0 = m0 * fmax(0, fmin(e0.dy, y + d0 - e0.y0)) + e0.x0,
- x1 = m1 * fmax(0, fmin(e1.dy, y + d1 - e1.y0)) + e1.x0;
- scanLine(floor(x1), ceil(x0), y, ymax);
+ double x0 = m0 * std::fmax(0, std::fmin(e0.dy, y + d0 - e0.y0)) + e0.x0,
+ x1 = m1 * std::fmax(0, std::fmin(e1.dy, y + d1 - e1.y0)) + e1.x0;
+ scanLine(std::floor(x1), std::ceil(x0), y, ymax);
}
}
@@ -357,7 +357,7 @@ double Source::getZoom() const {
}
std::forward_list<llmr::Tile::ID> Source::covering_tiles(int32_t zoom, const box& points) {
- int32_t dim = pow(2, zoom);
+ int32_t dim = std::pow(2, zoom);
std::forward_list<llmr::Tile::ID> tiles;
bool is_raster = (type == Type::raster);
double search_zoom = getZoom();
@@ -389,8 +389,8 @@ std::forward_list<llmr::Tile::ID> Source::covering_tiles(int32_t zoom, const box
const vec2<double>& center = points.center;
tiles.sort([&center](const Tile::ID& a, const Tile::ID& b) {
// Sorts by distance from the box center
- return fabs(a.x - center.x) + fabs(a.y - center.y) <
- fabs(b.x - center.x) + fabs(b.y - center.y);
+ return std::fabs(a.x - center.x) + std::fabs(a.y - center.y) <
+ std::fabs(b.x - center.x) + std::fabs(b.y - center.y);
});
tiles.unique();
diff --git a/src/map/tile.cpp b/src/map/tile.cpp
index 5e22dd0bb2..45fe88ee29 100644
--- a/src/map/tile.cpp
+++ b/src/map/tile.cpp
@@ -12,7 +12,7 @@ Tile::Tile(const ID& id)
Tile::ID Tile::ID::parent(int8_t parent_z) const {
assert(parent_z < z);
- int32_t dim = pow(2, z - parent_z);
+ int32_t dim = std::pow(2, z - parent_z);
return Tile::ID{
parent_z,
(x >= 0 ? x : x - dim + 1) / dim,
@@ -22,7 +22,7 @@ Tile::ID Tile::ID::parent(int8_t parent_z) const {
std::forward_list<Tile::ID> Tile::ID::children(int32_t child_z) const {
assert(child_z > z);
- int32_t factor = pow(2, child_z - z);
+ int32_t factor = std::pow(2, child_z - z);
std::forward_list<ID> children;
for (int32_t ty = y * factor, y_max = (y + 1) * factor; ty < y_max; ++ty) {
@@ -34,7 +34,7 @@ std::forward_list<Tile::ID> Tile::ID::children(int32_t child_z) const {
}
Tile::ID Tile::ID::normalized() const {
- int32_t dim = pow(2, z);
+ int32_t dim = std::pow(2, z);
int32_t nx = x, ny = y;
while (nx < 0) nx += dim;
while (nx >= dim) nx -= dim;
@@ -45,7 +45,7 @@ bool Tile::ID::isChildOf(const Tile::ID &parent) const {
if (parent.z >= z || parent.w != w) {
return false;
}
- int32_t scale = pow(2, z - parent.z);
+ int32_t scale = std::pow(2, z - parent.z);
return parent.x == ((x < 0 ? x - scale + 1 : x) / scale) &&
parent.y == y / scale;
}
diff --git a/src/map/transform.cpp b/src/map/transform.cpp
index d8ab9a7440..fb3458adef 100644
--- a/src/map/transform.cpp
+++ b/src/map/transform.cpp
@@ -49,8 +49,8 @@ void Transform::moveBy(const double dx, const double dy, const time duration) {
void Transform::_moveBy(const double dx, const double dy, const time duration) {
// This is only called internally, so we don't need a lock here.
- final.x = current.x + cos(current.angle) * dx + sin(current.angle) * dy;
- final.y = current.y + cos(current.angle) * dy + sin(-current.angle) * dx;
+ final.x = current.x + std::cos(current.angle) * dx + std::sin(current.angle) * dy;
+ final.y = current.y + std::cos(current.angle) * dy + std::sin(-current.angle) * dx;
if (duration == 0) {
current.x = final.x;
@@ -68,9 +68,9 @@ void Transform::_moveBy(const double dx, const double dy, const time duration) {
void Transform::setLonLat(const double lon, const double lat, const time duration) {
uv::writelock lock(mtx);
- const double f = fmin(fmax(sin(D2R * lat), -0.9999), 0.9999);
- double xn = -round(lon * Bc);
- double yn = round(0.5 * Cc * log((1 + f) / (1 - f)));
+ const double f = std::fmin(std::fmax(std::sin(D2R * lat), -0.9999), 0.9999);
+ double xn = -std::round(lon * Bc);
+ double yn = std::round(0.5 * Cc * std::log((1 + f) / (1 - f)));
_setScaleXY(current.scale, xn, yn, duration);
}
@@ -79,16 +79,16 @@ void Transform::setLonLatZoom(const double lon, const double lat, const double z
const time duration) {
uv::writelock lock(mtx);
- double new_scale = pow(2.0, zoom);
+ double new_scale = std::pow(2.0, zoom);
const double s = new_scale * util::tileSize;
zc = s / 2;
Bc = s / 360;
Cc = s / (2 * M_PI);
- const double f = fmin(fmax(sin(D2R * lat), -0.9999), 0.9999);
- double xn = -round(lon * Bc);
- double yn = round(0.5 * Cc * log((1 + f) / (1 - f)));
+ const double f = std::fmin(std::fmax(std::sin(D2R * lat), -0.9999), 0.9999);
+ double xn = -std::round(lon * Bc);
+ double yn = std::round(0.5 * Cc * log((1 + f) / (1 - f)));
_setScaleXY(new_scale, xn, yn, duration);
}
@@ -97,7 +97,7 @@ void Transform::getLonLat(double &lon, double &lat) const {
uv::readlock lock(mtx);
lon = -final.x / Bc;
- lat = R2D * (2 * atan(exp(final.y / Cc)) - 0.5 * M_PI);
+ lat = R2D * (2 * std::atan(std::exp(final.y / Cc)) - 0.5 * M_PI);
}
void Transform::getLonLatZoom(double &lon, double &lat, double &zoom) const {
@@ -159,7 +159,7 @@ void Transform::setScale(const double scale, const double cx, const double cy,
void Transform::setZoom(const double zoom, const time duration) {
uv::writelock lock(mtx);
- _setScale(pow(2.0, zoom), -1, -1, duration);
+ _setScale(std::pow(2.0, zoom), -1, -1, duration);
}
double Transform::getZoom() const {
@@ -224,8 +224,8 @@ void Transform::_setScale(double new_scale, double cx, double cy, const time dur
const double dy = (cy - current.height / 2) * (1.0 - factor);
// Account for angle
- const double angle_sin = sin(-current.angle);
- const double angle_cos = cos(-current.angle);
+ const double angle_sin = std::sin(-current.angle);
+ const double angle_cos = std::cos(-current.angle);
const double ax = angle_cos * dx - angle_sin * dy;
const double ay = angle_sin * dx + angle_cos * dy;
@@ -276,15 +276,15 @@ void Transform::rotateBy(const double start_x, const double start_y, const doubl
const double begin_center_y = start_y - center_y;
const double beginning_center_dist =
- sqrt(begin_center_x * begin_center_x + begin_center_y * begin_center_y);
+ std::sqrt(begin_center_x * begin_center_x + begin_center_y * begin_center_y);
// If the first click was too close to the center, move the center of rotation by 200 pixels
// in the direction of the click.
if (beginning_center_dist < 200) {
const double offset_x = -200, offset_y = 0;
- const double rotate_angle = atan2(begin_center_y, begin_center_x);
- const double rotate_angle_sin = sin(rotate_angle);
- const double rotate_angle_cos = cos(rotate_angle);
+ const double rotate_angle = std::atan2(begin_center_y, begin_center_x);
+ const double rotate_angle_sin = std::sin(rotate_angle);
+ const double rotate_angle_cos = std::cos(rotate_angle);
center_x = start_x + rotate_angle_cos * offset_x - rotate_angle_sin * offset_y;
center_y = start_y + rotate_angle_sin * offset_x + rotate_angle_cos * offset_y;
}
diff --git a/src/map/transform_state.cpp b/src/map/transform_state.cpp
index c6f8be71b3..b6a4e5bb25 100644
--- a/src/map/transform_state.cpp
+++ b/src/map/transform_state.cpp
@@ -6,7 +6,7 @@ using namespace llmr;
#pragma mark - Matrix
void TransformState::matrixFor(mat4& matrix, const Tile::ID& id) const {
- const double tile_scale = pow(2, id.z);
+ const double tile_scale = std::pow(2, id.z);
const double tile_size = scale * util::tileSize / tile_scale;
matrix::identity(matrix);
@@ -23,10 +23,10 @@ void TransformState::matrixFor(mat4& matrix, const Tile::ID& id) const {
}
box TransformState::cornersToBox(uint32_t z) const {
- const double ref_scale = pow(2, z);
+ const double ref_scale = std::pow(2, z);
- const double angle_sin = sin(-angle);
- const double angle_cos = cos(-angle);
+ const double angle_sin = std::sin(-angle);
+ const double angle_cos = std::cos(-angle);
const double w_2 = width / 2;
const double h_2 = height / 2;
@@ -88,15 +88,15 @@ float TransformState::getPixelRatio() const {
#pragma mark - Zoom
float TransformState::getNormalizedZoom() const {
- return log(scale * util::tileSize / 256.0f) / M_LN2;
+ return std::log(scale * util::tileSize / 256.0f) / M_LN2;
}
int32_t TransformState::getIntegerZoom() const {
- return floor(getZoom());
+ return std::floor(getZoom());
}
double TransformState::getZoom() const {
- return log(scale) / M_LN2;
+ return std::log(scale) / M_LN2;
}
double TransformState::getScale() const {
diff --git a/src/renderer/fill_bucket.cpp b/src/renderer/fill_bucket.cpp
index e4783c5c3e..2a4e1c78ab 100644
--- a/src/renderer/fill_bucket.cpp
+++ b/src/renderer/fill_bucket.cpp
@@ -155,7 +155,7 @@ void FillBucket::tessellate() {
for (size_t i = 0; i < vertex_count; ++i) {
if (vertex_indices[i] == TESS_UNDEF) {
- vertexBuffer.add(round(vertices[i * 2]), round(vertices[i * 2 + 1]));
+ vertexBuffer.add(std::round(vertices[i * 2]), std::round(vertices[i * 2 + 1]));
vertex_indices[i] = (TESSindex)total_vertex_count;
total_vertex_count++;
}
diff --git a/src/renderer/line_bucket.cpp b/src/renderer/line_bucket.cpp
index f968c56cbf..a253d495d0 100644
--- a/src/renderer/line_bucket.cpp
+++ b/src/renderer/line_bucket.cpp
@@ -159,12 +159,12 @@ void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
double joinAngularity = nextNormal.x * joinNormal.y - nextNormal.y * joinNormal.x;
joinNormal.x /= joinAngularity;
joinNormal.y /= joinAngularity;
- double roundness = fmax(abs(joinNormal.x), abs(joinNormal.y));
+ double roundness = std::fmax(std::abs(joinNormal.x), std::abs(joinNormal.y));
// Switch to miter joins if the angle is very low.
if (currentJoin != JoinType::Miter) {
- if (fabs(joinAngularity) < 0.5 && roundness < miterLimit) {
+ if (std::fabs(joinAngularity) < 0.5 && roundness < miterLimit) {
currentJoin = JoinType::Miter;
}
}
@@ -209,7 +209,7 @@ void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
else if (currentJoin == JoinType::Miter) {
// MITER JOIN
- if (fabs(joinAngularity) < 0.01) {
+ if (std::fabs(joinAngularity) < 0.01) {
// The two normals are almost parallel.
joinNormal.x = -nextNormal.y;
joinNormal.y = nextNormal.x;
diff --git a/src/renderer/painter.cpp b/src/renderer/painter.cpp
index 7c5578829a..c6c4a79322 100644
--- a/src/renderer/painter.cpp
+++ b/src/renderer/painter.cpp
@@ -189,8 +189,8 @@ mat4 Painter::translatedMatrix(const std::array<float, 2> &translation, const Ti
mat4 result;
if (anchor == TranslateAnchor::Viewport) {
- const double sin_a = sin(-map.getState().getAngle());
- const double cos_a = cos(-map.getState().getAngle());
+ const double sin_a = std::sin(-map.getState().getAngle());
+ const double cos_a = std::cos(-map.getState().getAngle());
matrix::translate(result, matrix,
factor * (translation[0] * cos_a - translation[1] * sin_a),
factor * (translation[0] * sin_a + translation[1] * cos_a),
diff --git a/src/renderer/painter_fill.cpp b/src/renderer/painter_fill.cpp
index 442f627a5c..b412d85707 100644
--- a/src/renderer/painter_fill.cpp
+++ b/src/renderer/painter_fill.cpp
@@ -77,8 +77,8 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons
// Draw texture fill
ImagePosition imagePos = sprite->getPosition(properties.image, true);
- float factor = 8.0 / pow(2, map.getState().getIntegerZoom() - id.z);
- float mix = fmod(map.getState().getZoom(), 1.0);
+ float factor = 8.0 / std::pow(2, map.getState().getIntegerZoom() - id.z);
+ float mix = std::fmod(map.getState().getZoom(), 1.0);
std::array<float, 2> imageSize = {{
imagePos.size.x * factor,
@@ -87,8 +87,8 @@ void Painter::renderFill(FillBucket& bucket, const std::string& layer_name, cons
};
std::array<float, 2> offset = {{
- (float)fmod(id.x * 4096, imageSize[0]),
- (float)fmod(id.y * 4096, imageSize[1])
+ (float)std::fmod(id.x * 4096, imageSize[0]),
+ (float)std::fmod(id.y * 4096, imageSize[1])
}
};
diff --git a/src/renderer/painter_line.cpp b/src/renderer/painter_line.cpp
index ccd916c521..6856c93af1 100644
--- a/src/renderer/painter_line.cpp
+++ b/src/renderer/painter_line.cpp
@@ -21,8 +21,8 @@ void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, cons
// These are the radii of the line. We are limiting it to 16, which will result
// in a point size of 64 on retina.
- float inset = fmin((fmax(-1, offset - width / 2 - 0.5) + 1), 16.0f);
- float outset = fmin(offset + width / 2 + 0.5, 16.0f);
+ float inset = std::fmin((std::fmax(-1, offset - width / 2 - 0.5) + 1), 16.0f);
+ float outset = std::fmin(offset + width / 2 + 0.5, 16.0f);
Color color = properties.color;
color[0] *= properties.opacity;
@@ -53,7 +53,7 @@ void Painter::renderLine(LineBucket& bucket, const std::string& layer_name, cons
}
});
- float pointSize = ceil(map.getState().getPixelRatio() * outset * 2.0);
+ float pointSize = std::ceil(map.getState().getPixelRatio() * outset * 2.0);
#if defined(GL_ES_VERSION_2_0)
linejoinShader->setSize(pointSize);
#else
diff --git a/src/renderer/painter_text.cpp b/src/renderer/painter_text.cpp
index a17f162e93..d1abbb5261 100644
--- a/src/renderer/painter_text.cpp
+++ b/src/renderer/painter_text.cpp
@@ -28,7 +28,7 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons
}
// If layerStyle.size > bucket.info.fontSize then labels may collide
- float fontSize = fmin(properties.size, bucket.geom_desc.font_size);
+ float fontSize = std::fmin(properties.size, bucket.geom_desc.font_size);
matrix::scale(exMatrix, exMatrix, fontSize / 24.0f, fontSize / 24.0f, 1.0f);
const mat4 vtxMatrix = translatedMatrix(properties.translate, id, properties.translateAnchor);
@@ -44,7 +44,7 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons
textShader->setGamma(2.5f / fontSize / map.getState().getPixelRatio());
// Convert the -pi..pi to an int8 range.
- float angle = round((map.getState().getAngle() + rotate) / M_PI * 128);
+ float angle = std::round((map.getState().getAngle() + rotate) / M_PI * 128);
// adjust min/max zooms for variable font sies
float zoomAdjust = log(fontSize / bucket.geom_desc.font_size) / log(2);
@@ -75,8 +75,8 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons
float startingZ = history.front().z;
const FrameSnapshot lastFrame = history.back();
float endingZ = lastFrame.z;
- float lowZ = fmin(startingZ, endingZ);
- float highZ = fmax(startingZ, endingZ);
+ float lowZ = std::fmin(startingZ, endingZ);
+ float highZ = std::fmax(startingZ, endingZ);
// Calculate the speed of zooming, and how far it would zoom in terms of zoom levels in one duration
float zoomDiff = endingZ - history[1].z,
@@ -91,8 +91,8 @@ void Painter::renderText(TextBucket& bucket, const std::string& layer_name, cons
float bump = (currentTime - lastFrame.timestamp) / duration * fadedist;
textShader->setFadeDist(fadedist * 10);
- textShader->setMinFadeZoom(floor(lowZ * 10));
- textShader->setMaxFadeZoom(floor(highZ * 10));
+ textShader->setMinFadeZoom(std::floor(lowZ * 10));
+ textShader->setMaxFadeZoom(std::floor(highZ * 10));
textShader->setFadeZoom((map.getState().getZoom() + bump) * 10);
// We're drawing in the translucent pass which is bottom-to-top, so we need
diff --git a/src/style/properties.cpp b/src/style/properties.cpp
index 46e84ce9b0..6563d54316 100644
--- a/src/style/properties.cpp
+++ b/src/style/properties.cpp
@@ -52,7 +52,7 @@ float functions::stops(float z, const std::vector<float>& stops) {
// Linear interpolation if base is 0
if (smaller_val == 0) return factor * larger_val;
// Exponential interpolation between the values
- return smaller_val * pow(larger_val / smaller_val, factor);
+ return smaller_val * std::pow(larger_val / smaller_val, factor);
} else if (larger || smaller) {
// Do not draw a line.
return -std::numeric_limits<float>::infinity();
@@ -77,7 +77,7 @@ float functions::linear(float z, const std::vector<float>& values) {
const float min = values[3];
const float max = values[4];
- return fmin(fmax(min, val + (z - z_base) * slope), max);
+ return std::fmin(std::fmax(min, val + (z - z_base) * slope), max);
}
float functions::exponential(float z, const std::vector<float>& values) {
@@ -91,5 +91,5 @@ float functions::exponential(float z, const std::vector<float>& values) {
const float min = values[3];
const float max = values[4];
- return fmin(fmax(min, val + pow(1.75, (z - z_base)) * slope), max);
+ return std::fmin(std::fmax(min, val + std::pow(1.75, (z - z_base)) * slope), max);
}
diff --git a/src/text/collision.cpp b/src/text/collision.cpp
index ddfa90a1d4..e8bd24153d 100644
--- a/src/text/collision.cpp
+++ b/src/text/collision.cpp
@@ -104,7 +104,7 @@ PlacementProperty Collision::place(const PlacedGlyphs &placed_glyphs,
const CollisionRect &box = glyph.box;
float x12 = box.tl.x * box.tl.x, y12 = box.tl.y * box.tl.y,
x22 = box.br.x * box.br.x, y22 = box.br.y * box.br.y,
- diag = sqrt(
+ diag = std::sqrt(
util::max(x12 + y12, x12 + y22, x22 + y12, x22 + y22));
glyph.bbox = CollisionRect{{-diag, -diag}, {diag, diag}};
@@ -147,7 +147,7 @@ float Collision::getPlacementScale(const GlyphBoxes &glyphs,
return -1;
}
- float minScale = fmax(minPlacementScale, glyph.minScale);
+ float minScale = std::fmax(minPlacementScale, glyph.minScale);
float maxScale = glyph.maxScale;
if (minScale >= maxScale) {
@@ -184,7 +184,7 @@ float Collision::getPlacementScale(const GlyphBoxes &glyphs,
}
// todo: unhardcode the 8 = tileExtent/tileSize
- float padding = fmax(pad, placement.padding) * 8.0f;
+ float padding = std::fmax(pad, placement.padding) * 8.0f;
// Original algorithm:
float s1 = (ob.tl.x - nb.br.x - padding) /
@@ -207,7 +207,7 @@ float Collision::getPlacementScale(const GlyphBoxes &glyphs,
s3 = s4 = 1;
}
- float collisionFreeScale = fmin(fmax(s1, s2), fmax(s3, s4));
+ float collisionFreeScale = std::fmin(std::fmax(s1, s2), std::fmax(s3, s4));
// Only update label's min scale if the glyph was
// restricted by a collision
@@ -278,12 +278,12 @@ PlacementRange Collision::getPlacementRange(const GlyphBoxes &glyphs,
if (!(intersectX && intersectY))
continue;
- float scale = fmax(placementScale, b.placementScale);
+ float scale = std::fmax(placementScale, b.placementScale);
// TODO? glyph.box or glyph.bbox?
CollisionRange range = rotationRange(glyph, b, scale);
- placementRange[0] = fmin(placementRange[0], range[0]);
- placementRange[1] = fmax(placementRange[1], range[1]);
+ placementRange[0] = std::fmin(placementRange[0], range[0]);
+ placementRange[1] = std::fmax(placementRange[1], range[1]);
}
}
@@ -300,7 +300,7 @@ void Collision::insert(const GlyphBoxes &glyphs, const CollisionAnchor &anchor,
const CollisionRect &bbox = glyph.bbox;
const CollisionRect &box = glyph.box;
- float minScale = fmax(placementScale, glyph.minScale);
+ float minScale = std::fmax(placementScale, glyph.minScale);
Box bounds{Point{anchor.x + bbox.tl.x / minScale,
anchor.y + bbox.tl.y / minScale},
diff --git a/src/text/placement.cpp b/src/text/placement.cpp
index 15cb787511..5c8b154741 100644
--- a/src/text/placement.cpp
+++ b/src/text/placement.cpp
@@ -28,7 +28,7 @@ Placement::Placement(int8_t zoom)
// glyphs be placed, slowing down collision checking. Only place labels if
// they will show up within the intended zoom range of the tile.
// TODO make this not hardcoded to 3
- maxPlacementScale(exp(log(2) * util::min((25.5 - zoom), 3.0))) {}
+ maxPlacementScale(std::exp(log(2) * util::min((25.5 - zoom), 3.0))) {}
bool byScale(const Anchor &a, const Anchor &b) { return a.scale < b.scale; }
@@ -95,20 +95,20 @@ void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs,
float prevscale = std::numeric_limits<float>::infinity();
float prevAngle = 0.0f;
- offset = fabs(offset);
+ offset = std::fabs(offset);
const float placementScale = anchor.scale;
while (true) {
const float dist = util::dist<float>(newAnchor, end);
const float scale = offset / dist;
- float angle = -atan2(end.x - newAnchor.x, end.y - newAnchor.y) +
+ float angle = -std::atan2(end.x - newAnchor.x, end.y - newAnchor.y) +
direction * M_PI / 2.0f;
if (upsideDown)
angle += M_PI;
// Don't place around sharp corners
- float angleDiff = fmod((angle - prevAngle), (2.0f * M_PI));
+ float angleDiff = std::fmod((angle - prevAngle), (2.0f * M_PI));
if (prevAngle && angleDiff > maxAngleDelta) {
anchor.scale = prevscale;
break;
@@ -120,7 +120,7 @@ void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs,
/* minScale */ scale,
/* maxScale */ prevscale,
/* angle */ static_cast<float>(
- fmod((angle + 2.0 * M_PI), (2.0 * M_PI)))};
+ std::fmod((angle + 2.0 * M_PI), (2.0 * M_PI)))};
if (scale <= placementScale)
break;
@@ -228,8 +228,8 @@ PlacedGlyphs getGlyphs(Anchor &anchor, float advance, const Shaping &shaping,
if (angle) {
// Compute the transformation matrix.
- float angle_sin = sin(angle);
- float angle_cos = cos(angle);
+ float angle_sin = std::sin(angle);
+ float angle_cos = std::cos(angle);
std::array<float, 4> matrix = {
{angle_cos, -angle_sin, angle_sin, angle_cos}};
@@ -251,7 +251,7 @@ PlacedGlyphs getGlyphs(Anchor &anchor, float advance, const Shaping &shaping,
glyphs.emplace_back(PlacedGlyph{
tl, tr, bl, br, glyph.rect, width, height,
static_cast<float>(
- fmod((anchor.angle + rotate + instance.offset + 2 * M_PI),
+ std::fmod((anchor.angle + rotate + instance.offset + 2 * M_PI),
(2 * M_PI))),
GlyphBox{box, instance.minScale, instance.maxScale,
instance.anchor, horizontal}});
diff --git a/src/text/rotation_range.cpp b/src/text/rotation_range.cpp
index 3c1244763f..9cbf958b71 100644
--- a/src/text/rotation_range.cpp
+++ b/src/text/rotation_range.cpp
@@ -54,19 +54,19 @@ rotatingRotatingCollisions(const CollisionRect &a, const CollisionRect &b,
// Calculate angles at which collisions may occur
const std::array<float, 8> c = {{
// top/bottom
- /*[0]*/ static_cast<float>(asin((float)(a.br.y - b.tl.y) / d)),
- /*[1]*/ static_cast<float>(asin((float)(a.br.y - b.tl.y) / d) + M_PI),
+ /*[0]*/ static_cast<float>(std::asin((float)(a.br.y - b.tl.y) / d)),
+ /*[1]*/ static_cast<float>(std::asin((float)(a.br.y - b.tl.y) / d) + M_PI),
/*[2]*/ static_cast<float>(2 * M_PI -
- asin((float)(-a.tl.y + b.br.y) / d)),
- /*[3]*/ static_cast<float>(M_PI - asin((float)(-a.tl.y + b.br.y) / d)),
+ std::asin((float)(-a.tl.y + b.br.y) / d)),
+ /*[3]*/ static_cast<float>(M_PI - std::asin((float)(-a.tl.y + b.br.y) / d)),
// left/right
/*[4]*/ static_cast<float>(2 * M_PI -
- acos((float)(a.br.x - b.tl.x) / d)),
- /*[5]*/ static_cast<float>(acos((float)(a.br.x - b.tl.x) / d)),
- /*[6]*/ static_cast<float>(M_PI - acos((float)(-a.tl.x + b.br.x) / d)),
+ std::acos((float)(a.br.x - b.tl.x) / d)),
+ /*[5]*/ static_cast<float>(std::acos((float)(a.br.x - b.tl.x) / d)),
+ /*[6]*/ static_cast<float>(M_PI - std::acos((float)(-a.tl.x + b.br.x) / d)),
/*[7]*/ static_cast<float>(M_PI +
- acos((float)(-a.tl.x + b.br.x) / d))}};
+ std::acos((float)(-a.tl.x + b.br.x) / d))}};
const float rl = a.br.x - b.tl.x;
const float lr = -a.tl.x + b.br.x;
@@ -98,7 +98,7 @@ rotatingRotatingCollisions(const CollisionRect &a, const CollisionRect &b,
// between anchors.
// Convert the angles to angles from north.
f.push_back(
- fmod((c[i] + angleBetweenAnchors + 2 * M_PI), (2 * M_PI)));
+ std::fmod((c[i] + angleBetweenAnchors + 2 * M_PI), (2 * M_PI)));
}
}
@@ -117,7 +117,7 @@ rotatingRotatingCollisions(const CollisionRect &a, const CollisionRect &b,
double getAngle(const CollisionPoint &p1, const CollisionPoint &p2,
CollisionAngle d, const CollisionPoint &corner) {
- return fmod(util::angle_between(util::interp(p1.x, p2.x, d),
+ return std::fmod(util::angle_between(util::interp(p1.x, p2.x, d),
util::interp(p1.y, p2.y, d), corner.x,
corner.y) +
2 * M_PI,
@@ -141,8 +141,8 @@ void circleEdgeCollisions(std::back_insert_iterator<CollisionAngles> angles,
// a collision exists only if line intersects circle at two points
if (discriminant > 0) {
- CollisionAngle x1 = (-b - sqrt(discriminant)) / (2 * a);
- CollisionAngle x2 = (-b + sqrt(discriminant)) / (2 * a);
+ CollisionAngle x1 = (-b - std::sqrt(discriminant)) / (2 * a);
+ CollisionAngle x2 = (-b + std::sqrt(discriminant)) / (2 * a);
// only add points if within line segment
// hack to handle floating point representations of 0 and 1
diff --git a/src/util/mat4.cpp b/src/util/mat4.cpp
index e86c9e35e2..5f9f50bcd2 100644
--- a/src/util/mat4.cpp
+++ b/src/util/mat4.cpp
@@ -113,8 +113,8 @@ void matrix::translate(mat4& out, const mat4& a, float x, float y, float z) {
}
void matrix::rotate_z(mat4& out, const mat4& a, float rad) {
- float s = sin(rad),
- c = cos(rad),
+ float s = std::sin(rad),
+ c = std::cos(rad),
a00 = a[0],
a01 = a[1],
a02 = a[2],
diff --git a/test/rotation_range.cpp b/test/rotation_range.cpp
index 41b23f1f83..cb7ee07425 100644
--- a/test/rotation_range.cpp
+++ b/test/rotation_range.cpp
@@ -49,8 +49,8 @@ TEST(RotationRange, rotatingFixedCollisions) {
CollisionRect{CollisionPoint{1.4142, -10}, CollisionPoint{10, 10}});
EXPECT_EQ(1, collisions.size());
- EXPECT_EQ(135, round(deg(collisions.front()[0])));
- EXPECT_EQ(135, round(deg(collisions.front()[1])));
+ EXPECT_EQ(135, std::round(deg(collisions.front()[0])));
+ EXPECT_EQ(135, std::round(deg(collisions.front()[1])));
}
TEST(RotationRange, cornerBoxCollisions) {
@@ -122,10 +122,10 @@ TEST(RotationRange, rotatingRotatingCollisions) {
CollisionAnchor{1, 1});
EXPECT_EQ(2, c.size());
- EXPECT_EQ(135, round(deg(c[0][0])));
- EXPECT_EQ(135, round(deg(c[0][1])));
- EXPECT_EQ(315, round(deg(c[1][0])));
- EXPECT_EQ(315, round(deg(c[1][1])));
+ EXPECT_EQ(135, std::round(deg(c[0][0])));
+ EXPECT_EQ(135, std::round(deg(c[0][1])));
+ EXPECT_EQ(315, std::round(deg(c[1][0])));
+ EXPECT_EQ(315, std::round(deg(c[1][1])));
}
{