Merge branch 'master' into outdoors-style

Conflicts:
	bin/style.js
	include/llmr/map/transform.hpp
	src/renderer/painter.cpp
	src/text/placement.cpp
This commit is contained in:
Konstantin Käfer
2014-05-14 17:42:10 +02:00
30 changed files with 176 additions and 169 deletions

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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 {