diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-03-26 12:21:33 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-03-26 12:21:33 +0100 |
commit | 0c6f993695f403b89453b2410b48455d0885097f (patch) | |
tree | 013e61cf6958ff4fde6a73e0d505512cd0ffd3f9 /include | |
parent | 700dcc9260a57b7ccdd9a93fcecbca73640104ac (diff) | |
download | qtlocation-mapboxgl-0c6f993695f403b89453b2410b48455d0885097f.tar.gz |
add min/max functions and refactor FunctionProperty
fixes #83
Diffstat (limited to 'include')
-rw-r--r-- | include/llmr/style/properties.hpp | 51 | ||||
-rw-r--r-- | include/llmr/style/style.hpp | 10 | ||||
-rw-r--r-- | include/llmr/style/style_parser.hpp | 5 |
3 files changed, 23 insertions, 43 deletions
diff --git a/include/llmr/style/properties.hpp b/include/llmr/style/properties.hpp index 10299d0513..47b6ff195c 100644 --- a/include/llmr/style/properties.hpp +++ b/include/llmr/style/properties.hpp @@ -34,40 +34,31 @@ enum class Property { namespace functions { float null(float z, const std::vector<float>&); -bool null(float z, const std::vector<bool>&); - float constant(float z, const std::vector<float>& values); -bool constant(float z, const std::vector<bool>& values); - +float min(float z, const std::vector<float>& values); +float max(float z, const std::vector<float>& values); float stops(float z, const std::vector<float>& values); -bool stops(float z, const std::vector<bool>& values); - float linear(float z, const std::vector<float>& values); -bool linear(float z, const std::vector<bool>& values); - float exponential(float z, const std::vector<float>& values); -bool exponential(float z, const std::vector<bool>& values); } - -template <typename T> struct FunctionProperty { - typedef T (*fn)(float z, const std::vector<T>& values); + typedef float (*fn)(float z, const std::vector<float>& values); fn function; - std::vector<T> values; + std::vector<float> values; inline FunctionProperty() : function(&functions::null) {} - inline FunctionProperty(T value) : function(&functions::constant), values(1, value) {} - inline T operator()(float z) const { return function(z, values); } + inline FunctionProperty(float value) : function(&functions::constant), values(1, value) {} + template <typename T> inline T evaluate(float z) const { return function(z, values); } }; struct PointClass { - FunctionProperty<bool> enabled = true; - FunctionProperty<float> size; + FunctionProperty enabled = true; + FunctionProperty size; Color color = {{ 0, 0, 0, 1 }}; - FunctionProperty<float> opacity = 1; + FunctionProperty opacity = 1; std::string image; }; @@ -80,11 +71,11 @@ struct PointProperties { }; struct LineClass { - FunctionProperty<bool> enabled = true; - FunctionProperty<float> width; - FunctionProperty<float> offset; + FunctionProperty enabled = true; + FunctionProperty width; + FunctionProperty offset; Color color = {{ 0, 0, 0, 1 }}; - FunctionProperty<float> opacity = 1; + FunctionProperty opacity = 1; }; struct LineProperties { @@ -96,12 +87,12 @@ struct LineProperties { }; struct FillClass { - FunctionProperty<bool> enabled = true; + FunctionProperty enabled = true; Winding winding = Winding::NonZero; - FunctionProperty<bool> antialias = true; + FunctionProperty antialias = true; Color fill_color = {{ 0, 0, 0, 1 }}; Color stroke_color = {{ 0, 0, 0, std::numeric_limits<float>::infinity() }}; - FunctionProperty<float> opacity = 1; + FunctionProperty opacity = 1; std::string image; }; @@ -116,13 +107,13 @@ struct FillProperties { }; struct TextClass { - FunctionProperty<bool> enabled = true; + FunctionProperty enabled = true; Color color = {{ 0, 0, 0, 1 }}; Color halo = {{ 1, 1, 1, 0.75 }}; - FunctionProperty<float> haloRadius = 0.25f; - FunctionProperty<float> size = 12.0f; - FunctionProperty<float> rotate = 0.0f; - FunctionProperty<bool> alwaysVisible = false; + FunctionProperty haloRadius = 0.25f; + FunctionProperty size = 12.0f; + FunctionProperty rotate = 0.0f; + FunctionProperty alwaysVisible = false; }; struct TextProperties { diff --git a/include/llmr/style/style.hpp b/include/llmr/style/style.hpp index 2323228b03..a004df438a 100644 --- a/include/llmr/style/style.hpp +++ b/include/llmr/style/style.hpp @@ -30,16 +30,6 @@ public: void cascade(float z); -private: - static std::pair<std::string, BucketDescription> parseBucket(pbf data); - static LayerDescription parseLayer(pbf data); - static std::pair<std::string, ClassDescription> parseClass(pbf data); - static std::pair<std::string, FillClass> parseFillClass(pbf data); - static std::pair<std::string, LineClass> parseLineClass(pbf data); - static std::pair<std::string, PointClass> parsePointClass(pbf data); - template <typename T> static FunctionProperty<T> parseProperty(pbf data); - static Color parseColor(pbf& data); - public: std::shared_ptr<Sprite> sprite; diff --git a/include/llmr/style/style_parser.hpp b/include/llmr/style/style_parser.hpp index 93cd373b6c..60bb9a0504 100644 --- a/include/llmr/style/style_parser.hpp +++ b/include/llmr/style/style_parser.hpp @@ -30,9 +30,8 @@ private: std::string parseString(JSVal value); Color parseColor(JSVal value); Value parseValue(JSVal value); - template <typename T> typename FunctionProperty<T>::fn parseFunctionType(JSVal type); - FunctionProperty<float> parseFloatFunction(JSVal value); - FunctionProperty<bool> parseBoolFunction(JSVal value); + FunctionProperty::fn parseFunctionType(JSVal type); + FunctionProperty parseFunction(JSVal value); private: std::map<std::string, const rapidjson::Value *> constants; |