diff --git a/bin/style.js b/bin/style.js index 7ca40b612..691c91351 100644 --- a/bin/style.js +++ b/bin/style.js @@ -6,7 +6,7 @@ module.exports = { "@land": "#eee", "@water": "#999", "@park": "#bda", - "@road": "#fefefe", + "@road": "#FF00FF", "@border": "#6d90ab", "@building": "#ddd", "@building_outline": "#ccc", @@ -53,28 +53,26 @@ module.exports = { "fill-color": "blue" } }, { - "id": "roads", - "layers": [{ - "id": "road", - "source": "mapbox.mapbox-streets-v5", - "source-layer": "road", - "render": { - "type": "line", - "line-cap": "round", - "line-join": "bevel" - }, - "style": { - "line-color": "@road", - "line-blur": "@road_blur", - "line-width": { - "fn": "exponential", - "z": 10, - "val": -1, - "slope": 0.2, - "min": 1 - } + "id": "road", + "source": "mapbox.mapbox-streets-v5", + "source-layer": "road", + "render": { + "type": "line", + "line-cap": "round", + "line-join": "bevel" + }, + "style": { + "line-color": "@road", + "line-blur": "@road_blur", + "line-width": { + "fn": "exponential", + "z": 10, + "val": -1, + "slope": 0.2, + "min": 1, + "max": 1000 } - }] + } }, { "id": "building", "source": "mapbox.mapbox-streets-v5", diff --git a/include/llmr/style/function_properties.hpp b/include/llmr/style/function_properties.hpp index 970d617d0..d1e1a5b1c 100644 --- a/include/llmr/style/function_properties.hpp +++ b/include/llmr/style/function_properties.hpp @@ -1,43 +1,72 @@ #ifndef LLMR_STYLE_FUNCTION_PROPERTIES #define LLMR_STYLE_FUNCTION_PROPERTIES +#include + #include namespace llmr { -namespace functions { +template +struct ConstantFunction { + inline ConstantFunction(const T &value) : value(value) {} + inline T evaluate(float) const { return value; } -float null(float z, const std::vector&); -float constant(float z, const std::vector& values); -float min(float z, const std::vector& values); -float max(float z, const std::vector& values); -float stops(float z, const std::vector& values); -float linear(float z, const std::vector& values); -float exponential(float z, const std::vector& values); +private: + const T value; +}; -} +template +struct LinearFunction { + inline LinearFunction(const T &value, float z_base, float slope, const T &min, const T &max) + : value(value), min(min), max(max), z_base(z_base), slope(slope) {} + T evaluate(float z) const; -struct FunctionProperty { - typedef float (*fn)(float z, const std::vector& values); +private: + const T value, min, max; + const float z_base, slope; +}; - fn function; - std::vector values; +template +struct ExponentialFunction { + inline ExponentialFunction(const T &value, float z_base, float slope, const T &min, + const T &max) + : value(value), min(min), max(max), z_base(z_base), slope(slope) {} + T evaluate(float z) const; - inline FunctionProperty() : function(&functions::null) {} +private: + const T value, min, max; + const float z_base, slope; +}; - inline FunctionProperty(const FunctionProperty &property) - : function(property.function), values(property.values) {} - inline FunctionProperty(FunctionProperty &&property) - : function(property.function), values(std::move(property.values)) {} +template +struct StopsFunction { + inline StopsFunction(const std::vector> &values) : values(values) {} + T evaluate(float z) const; +private: + const std::vector> values; +}; - inline void operator=(const FunctionProperty &rhs) { - function = rhs.function; - values = rhs.values; +template +using Function = util::variant< + ConstantFunction, + LinearFunction, + ExponentialFunction, + StopsFunction +>; + +template +struct FunctionEvaluator { + typedef T result_type; + inline FunctionEvaluator(float z) : z(z) {} + + template