parse line width function and call tile destructor from main thread

This commit is contained in:
Konstantin Käfer
2014-01-29 12:25:50 +01:00
parent 04e16cf2ca
commit d5cae14770
9 changed files with 70 additions and 24 deletions

View File

@@ -2,6 +2,7 @@
#include <cassert>
#include <cmath>
using namespace llmr;
@@ -22,4 +23,48 @@ float functions::constant(float z, const std::vector<float>& values) {
bool functions::constant(float z, const std::vector<bool>& values) {
assert(values.size() == 1);
return values.front();
}
}
float functions::stops(float z, const std::vector<float>& stops) {
// We need an even number of stop values.
if (stops.size() % 2 != 0) return 0;
// Accounts for us rendering tiles at 512x512, so our zoom levels are shifted by 1.
z += 1;
bool smaller = false;
float smaller_z, smaller_val;
bool larger = false;
float larger_z, larger_val;
for (uint32_t i = 0; i < stops.size(); i += 2) {
float stop_z = stops[i];
float stop_val = stops[i + 1];
if (stop_z <= z && (!smaller || smaller_z < stop_z)) { smaller = true; smaller_z = stop_z; smaller_val = stop_val; }
if (stop_z >= z && (!larger || larger_z > stop_z)) { larger = true; larger_z = stop_z; larger_val = stop_val; }
}
if (smaller && larger) {
// Exponential interpolation between the values
if (larger_z == smaller_z) return smaller_val;
float val = smaller_val * pow(larger_val / smaller_val, (z - smaller_z) / (larger_z - smaller_z));
return val;
} else if (larger || smaller) {
// Do not draw a line.
return -std::numeric_limits<float>::infinity();
// Exponential extrapolation of the smaller or larger value
//var edge = larger || smaller;
//return Math.pow(2, z) * (edge.val / Math.pow(2, edge.z));
} else {
// No stop defined.
return 1;
}
}
bool functions::stops(float z, const std::vector<bool>& values) {
// TODO
return false;
}