diff --git a/include/llmr/style/properties.hpp b/include/llmr/style/properties.hpp index 3fae1537c..11b5a8f80 100644 --- a/include/llmr/style/properties.hpp +++ b/include/llmr/style/properties.hpp @@ -45,6 +45,9 @@ bool stops(float z, const std::vector& values); float linear(float z, const std::vector& values); bool linear(float z, const std::vector& values); +float exponential(float z, const std::vector& values); +bool exponential(float z, const std::vector& values); + } diff --git a/src/style/properties.cpp b/src/style/properties.cpp index 469ccc394..332f61249 100644 --- a/src/style/properties.cpp +++ b/src/style/properties.cpp @@ -89,3 +89,23 @@ bool functions::linear(float z, const std::vector&) { // TODO return false; } + +float functions::exponential(float z, const std::vector& 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 + pow(1.75, (z - z_base)) * slope), max); + // return fmin(fmax(min, val + (z - z_base) * slope), max); +} + +bool functions::exponential(float z, const std::vector&) { + // TODO + return false; +} diff --git a/src/style/style_parser.cpp b/src/style/style_parser.cpp index 9d4ee2cf6..6c92c1439 100644 --- a/src/style/style_parser.cpp +++ b/src/style/style_parser.cpp @@ -310,6 +310,8 @@ typename FunctionProperty::fn StyleParser::parseFunctionType(JSVal type) { return &functions::linear; } else if (t == "stops") { return &functions::stops; + } else if (t == "exponential") { + return &functions::exponential; } else { throw Style::exception("unknown function type"); }