diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-01-29 12:25:50 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-01-29 12:25:50 +0100 |
commit | d5cae1477048cf489704e39e7b7c71dc007bccb4 (patch) | |
tree | 928e3f2aa7deb9cdbabe9fac6051c195354778c5 /src/style | |
parent | 04e16cf2caf0c6f33c9e860879f3304b3c505fb8 (diff) | |
download | qtlocation-mapboxgl-d5cae1477048cf489704e39e7b7c71dc007bccb4.tar.gz |
parse line width function and call tile destructor from main thread
Diffstat (limited to 'src/style')
-rw-r--r-- | src/style/properties.cpp | 47 | ||||
-rw-r--r-- | src/style/style.cpp | 5 |
2 files changed, 49 insertions, 3 deletions
diff --git a/src/style/properties.cpp b/src/style/properties.cpp index 0ea3fbfeef..499f0c7276 100644 --- a/src/style/properties.cpp +++ b/src/style/properties.cpp @@ -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(); -}
\ No newline at end of file +} + + +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; +} + diff --git a/src/style/style.cpp b/src/style/style.cpp index 9d476aba0a..3b95fb8792 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -173,6 +173,7 @@ template <typename T> FunctionProperty<T> Style::parseProperty(pbf data) { switch((Property)data.varint()) { case Property::Null: property.function = &functions::null; break; case Property::Constant: property.function = &functions::constant; break; + case Property::Stops: property.function = &functions::stops; break; default: property.function = &functions::null; break; } } else if (data.tag == 2) { // value @@ -222,11 +223,11 @@ void Style::cascade(float z) { const std::string& layer_name = line_pair.first; const llmr::LineClass& layer = line_pair.second; - // TODO: This should be restricted to fill styles that have actual + // TODO: This should be restricted to line styles that have actual // values so as to not override with default values. llmr::LineProperties& stroke = computed.lines[layer_name]; stroke.hidden = layer.hidden(z); - stroke.width = 2; //layer.width(z); + stroke.width = layer.width(z); stroke.offset = layer.offset(z); stroke.color = layer.color; stroke.opacity = layer.opacity(z); |