diff options
author | Dane Springmeyer <dane@dbsgeo.com> | 2014-01-29 14:00:36 -0800 |
---|---|---|
committer | Dane Springmeyer <dane@dbsgeo.com> | 2014-01-29 14:00:36 -0800 |
commit | b70788a6f134f3b89763498c313594c8234379ed (patch) | |
tree | 25e774c7c3e64cb01bcde940bbd770db8cc5d597 /src/style | |
parent | 948a0d1922be92c924614f27d8b9ba761922af13 (diff) | |
parent | 2b59dfae6388f3ce4d38f8f9615c47d00b302518 (diff) | |
download | qtlocation-mapboxgl-b70788a6f134f3b89763498c313594c8234379ed.tar.gz |
Merge branch 'master' of github.com:mapbox/llmr-native into unique-cpp-names
Diffstat (limited to 'src/style')
-rw-r--r-- | src/style/bucket_description.cpp | 8 | ||||
-rw-r--r-- | src/style/properties.cpp | 67 | ||||
-rw-r--r-- | src/style/resources.cpp | 54 | ||||
-rw-r--r-- | src/style/style.cpp | 29 |
4 files changed, 117 insertions, 41 deletions
diff --git a/src/style/bucket_description.cpp b/src/style/bucket_description.cpp index 94d0b8115c..eb3b550bef 100644 --- a/src/style/bucket_description.cpp +++ b/src/style/bucket_description.cpp @@ -11,9 +11,9 @@ std::ostream& llmr::operator<<(std::ostream& os, const BucketDescription& bucket for (const Value& value : bucket.source_value) { os << " - source_value: " << value << std::endl; } - os << " - cap: " << (uint32_t)bucket.cap << std::endl; - os << " - join: " << (uint32_t)bucket.join << std::endl; - os << " - font: " << bucket.font << std::endl; - os << " - font_size: " << bucket.font_size << std::endl; + os << " - cap: " << (uint32_t)bucket.geometry.cap << std::endl; + os << " - join: " << (uint32_t)bucket.geometry.join << std::endl; + os << " - font: " << bucket.geometry.font << std::endl; + os << " - font_size: " << bucket.geometry.font_size << std::endl; return os; } diff --git a/src/style/properties.cpp b/src/style/properties.cpp index 0ea3fbfeef..a0f2a659df 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,68 @@ 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) { + if (larger_z == smaller_z || larger_val == smaller_val) return smaller_val; + float factor = (z - smaller_z) / (larger_z - smaller_z); + // 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); + } 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; +} + +float functions::linear(float z, const std::vector<float>& values) { + if (values.size() != 5) { + return 0; + } + + const float z_base = values[0]; + const float val = values[1]; + const float slope = values[2]; + const float min = values[3]; + const float max = values[4]; + + return fmin(fmax(min, val + (z - z_base) * slope), max); +} + +bool functions::linear(float z, const std::vector<bool>&) { + // TODO + return false; +} diff --git a/src/style/resources.cpp b/src/style/resources.cpp index 57bad8636f..8bd1ca1297 100644 --- a/src/style/resources.cpp +++ b/src/style/resources.cpp @@ -39,29 +39,35 @@ const unsigned char resources::style[] = { 116, 121, 112, 101, 50, 9, 10, 7, 65, 108, 99, 111, 104, 111, 108, 18, 12, 10, 4, 112, 97, 114, 107, 18, 4, 112, 97, 114, 107, 18, 12, 10, 4, 119, 111, 111, 100, 18, 4, 119, 111, 111, 100, 18, 14, 10, 5, 119, - 97, 116, 101, 114, 18, 5, 119, 97, 116, 101, 114, 18, 28, 10, 12, 114, - 111, 97, 100, 95, 108, 105, 109, 105, 116, 101, 100, 18, 12, 114, 111, 97, - 100, 95, 108, 105, 109, 105, 116, 101, 100, 18, 28, 10, 12, 114, 111, 97, - 100, 95, 114, 101, 103, 117, 108, 97, 114, 18, 12, 114, 111, 97, 100, 95, - 114, 101, 103, 117, 108, 97, 114, 18, 24, 10, 10, 114, 111, 97, 100, 95, - 108, 97, 114, 103, 101, 18, 10, 114, 111, 97, 100, 95, 108, 97, 114, 103, - 101, 18, 18, 10, 7, 97, 108, 99, 111, 104, 111, 108, 18, 7, 97, 108, - 99, 111, 104, 111, 108, 26, 128, 2, 10, 7, 100, 101, 102, 97, 117, 108, - 116, 18, 21, 10, 4, 112, 97, 114, 107, 34, 8, 8, 2, 18, 4, 0, - 0, 128, 63, 45, 255, 159, 223, 200, 18, 31, 10, 4, 119, 111, 111, 100, - 34, 8, 8, 2, 18, 4, 0, 0, 128, 63, 45, 255, 102, 170, 51, 58, - 8, 8, 2, 18, 4, 205, 204, 204, 61, 18, 22, 10, 5, 119, 97, 116, - 101, 114, 34, 8, 8, 2, 18, 4, 0, 0, 128, 63, 45, 255, 230, 182, - 115, 26, 41, 10, 12, 114, 111, 97, 100, 95, 108, 105, 109, 105, 116, 101, - 100, 29, 255, 187, 187, 187, 34, 20, 8, 3, 18, 16, 0, 0, 0, 0, - 0, 0, 128, 63, 0, 0, 160, 65, 0, 0, 128, 63, 26, 57, 10, 12, - 114, 111, 97, 100, 95, 114, 101, 103, 117, 108, 97, 114, 29, 255, 153, 153, - 153, 34, 36, 8, 3, 18, 32, 0, 0, 0, 0, 0, 0, 0, 63, 0, - 0, 80, 65, 0, 0, 0, 63, 0, 0, 128, 65, 0, 0, 0, 64, 0, - 0, 160, 65, 0, 0, 0, 66, 26, 63, 10, 10, 114, 111, 97, 100, 95, - 108, 97, 114, 103, 101, 29, 255, 102, 102, 102, 34, 44, 8, 3, 18, 40, - 0, 0, 0, 0, 0, 0, 0, 63, 0, 0, 48, 65, 0, 0, 0, 63, - 0, 0, 80, 65, 0, 0, 128, 63, 0, 0, 128, 65, 0, 0, 128, 64, - 0, 0, 160, 65, 0, 0, 128, 66 + 97, 116, 101, 114, 18, 5, 119, 97, 116, 101, 114, 18, 20, 10, 8, 98, + 117, 105, 108, 100, 105, 110, 103, 18, 8, 98, 117, 105, 108, 100, 105, 110, + 103, 18, 28, 10, 12, 114, 111, 97, 100, 95, 108, 105, 109, 105, 116, 101, + 100, 18, 12, 114, 111, 97, 100, 95, 108, 105, 109, 105, 116, 101, 100, 18, + 28, 10, 12, 114, 111, 97, 100, 95, 114, 101, 103, 117, 108, 97, 114, 18, + 12, 114, 111, 97, 100, 95, 114, 101, 103, 117, 108, 97, 114, 18, 24, 10, + 10, 114, 111, 97, 100, 95, 108, 97, 114, 103, 101, 18, 10, 114, 111, 97, + 100, 95, 108, 97, 114, 103, 101, 18, 18, 10, 7, 97, 108, 99, 111, 104, + 111, 108, 18, 7, 97, 108, 99, 111, 104, 111, 108, 26, 197, 2, 10, 7, + 100, 101, 102, 97, 117, 108, 116, 18, 21, 10, 4, 112, 97, 114, 107, 34, + 8, 8, 2, 18, 4, 0, 0, 128, 63, 45, 255, 159, 223, 200, 18, 31, + 10, 4, 119, 111, 111, 100, 34, 8, 8, 2, 18, 4, 0, 0, 128, 63, + 45, 255, 102, 170, 51, 58, 8, 8, 2, 18, 4, 205, 204, 204, 61, 18, + 22, 10, 5, 119, 97, 116, 101, 114, 34, 8, 8, 2, 18, 4, 0, 0, + 128, 63, 45, 255, 230, 182, 115, 18, 51, 10, 8, 98, 117, 105, 108, 100, + 105, 110, 103, 34, 8, 8, 2, 18, 4, 0, 0, 128, 63, 45, 255, 0, + 0, 0, 58, 24, 8, 4, 18, 20, 0, 0, 80, 65, 0, 0, 0, 0, + 205, 204, 204, 61, 0, 0, 0, 0, 205, 204, 204, 61, 26, 41, 10, 12, + 114, 111, 97, 100, 95, 108, 105, 109, 105, 116, 101, 100, 29, 255, 187, 187, + 187, 34, 20, 8, 3, 18, 16, 0, 0, 0, 0, 0, 0, 128, 63, 0, + 0, 240, 65, 0, 0, 128, 63, 26, 65, 10, 12, 114, 111, 97, 100, 95, + 114, 101, 103, 117, 108, 97, 114, 29, 255, 153, 153, 153, 34, 44, 8, 3, + 18, 40, 0, 0, 0, 0, 0, 0, 0, 63, 0, 0, 80, 65, 0, 0, + 0, 63, 0, 0, 128, 65, 0, 0, 0, 64, 0, 0, 160, 65, 0, 0, + 0, 66, 0, 0, 240, 65, 0, 0, 0, 66, 26, 71, 10, 10, 114, 111, + 97, 100, 95, 108, 97, 114, 103, 101, 29, 255, 102, 102, 102, 34, 52, 8, + 3, 18, 48, 0, 0, 0, 0, 0, 0, 0, 63, 0, 0, 48, 65, 0, + 0, 0, 63, 0, 0, 80, 65, 0, 0, 128, 63, 0, 0, 128, 65, 0, + 0, 128, 64, 0, 0, 160, 65, 0, 0, 128, 66, 0, 0, 240, 65, 0, + 0, 128, 66 }; const unsigned long resources::style_size = sizeof(resources::style); diff --git a/src/style/style.cpp b/src/style/style.cpp index a3a73c2526..3f6982feb0 100644 --- a/src/style/style.cpp +++ b/src/style/style.cpp @@ -47,13 +47,13 @@ std::pair<std::string, BucketDescription> Style::parseBucket(pbf data) { } else if (data.tag == 6) { // source_value bucket.source_value.emplace_back(parseValue(data.message())); } else if (data.tag == 7) { // cap - bucket.cap = (CapType)data.varint(); + bucket.geometry.cap = (CapType)data.varint(); } else if (data.tag == 8) { // join - bucket.join = (JoinType)data.varint(); + bucket.geometry.join = (JoinType)data.varint(); } else if (data.tag == 9) { // font - bucket.font = data.string(); + bucket.geometry.font = data.string(); } else if (data.tag == 10) { // font_size - bucket.font_size = data.float32(); + bucket.geometry.font_size = data.float32(); } else { data.skip(); } @@ -144,8 +144,10 @@ std::pair<std::string, LineClass> Style::parseLineClass(pbf data) { stroke.color = parseColor(data); } else if (data.tag == 4) { // width stroke.width = parseProperty<float>(data.message()); - } else if (data.tag == 5) { // opacity + } else if (data.tag == 5) { // offset stroke.offset = parseProperty<float>(data.message()); + } else if (data.tag == 6) { // opacity + stroke.opacity = parseProperty<float>(data.message()); } else { data.skip(); } @@ -158,11 +160,12 @@ std::pair<std::string, LineClass> Style::parseLineClass(pbf data) { Color Style::parseColor(pbf& data) { uint32_t rgba = data.fixed<uint32_t, 4>(); return {{ - (float)((rgba >> 24) & 0xFF) / 0xFF, - (float)((rgba >> 16) & 0xFF) / 0xFF, - (float)((rgba >> 8) & 0xFF) / 0xFF, - (float)((rgba >> 0) & 0xFF) / 0xFF - }}; + (float)((rgba >> 24) & 0xFF) / 0xFF, + (float)((rgba >> 16) & 0xFF) / 0xFF, + (float)((rgba >> 8) & 0xFF) / 0xFF, + (float)((rgba >> 0) & 0xFF) / 0xFF + } + }; } template <typename T> FunctionProperty<T> Style::parseProperty(pbf data) { @@ -170,9 +173,11 @@ template <typename T> FunctionProperty<T> Style::parseProperty(pbf data) { while (data.next()) { if (data.tag == 1) { // function - switch((Property)data.varint()) { + 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; + case Property::Linear: property.function = &functions::linear; break; default: property.function = &functions::null; break; } } else if (data.tag == 2) { // value @@ -222,7 +227,7 @@ 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); |