From 514485502db8ecacf2b11abad4599d7af09b0cf8 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Wed, 4 Jul 2018 23:12:58 +0300 Subject: Rename `HeatmapColorPropertyValue` to `ColorRampPropertyValue` Based on patch from @lbud (Lauren Budorick). Give `HeatmapColorPropertyValue` a more generic name, since the same value type will be used for both `heatmap-color` and `line-gradient` properties. --- include/mbgl/style/color_ramp_property_value.hpp | 49 ++++++++++++++++++++++ .../style/conversion/color_ramp_property_value.hpp | 49 ++++++++++++++++++++++ .../conversion/heatmap_color_property_value.hpp | 49 ---------------------- .../mbgl/style/heatmap_color_property_value.hpp | 49 ---------------------- include/mbgl/style/layers/heatmap_layer.hpp | 8 ++-- include/mbgl/style/layers/layer.hpp.ejs | 6 +-- 6 files changed, 105 insertions(+), 105 deletions(-) create mode 100644 include/mbgl/style/color_ramp_property_value.hpp create mode 100644 include/mbgl/style/conversion/color_ramp_property_value.hpp delete mode 100644 include/mbgl/style/conversion/heatmap_color_property_value.hpp delete mode 100644 include/mbgl/style/heatmap_color_property_value.hpp (limited to 'include') diff --git a/include/mbgl/style/color_ramp_property_value.hpp b/include/mbgl/style/color_ramp_property_value.hpp new file mode 100644 index 0000000000..3e93285d5a --- /dev/null +++ b/include/mbgl/style/color_ramp_property_value.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace style { + +/* + * Special-case implementation of (a subset of) the PropertyValue interface + * used for building the HeatmapColor paint property traits class. + */ +class ColorRampPropertyValue { +private: + std::shared_ptr value; + + friend bool operator==(const ColorRampPropertyValue& lhs, const ColorRampPropertyValue& rhs) { + return (lhs.isUndefined() && rhs.isUndefined()) || (lhs.value && rhs.value && *(lhs.value) == *(rhs.value)); + } + + friend bool operator!=(const ColorRampPropertyValue& lhs, const ColorRampPropertyValue& rhs) { + return !(lhs == rhs); + } + +public: + ColorRampPropertyValue() : value(nullptr) {} + ColorRampPropertyValue(std::shared_ptr value_) : value(std::move(value_)) {} + + bool isUndefined() const { return value.get() == nullptr; } + + // noop, needed for batch evaluation of paint property values to compile + template + Color evaluate(const Evaluator&, TimePoint = {}) const { return {}; } + + Color evaluate(double rampEvaluationParameter) const { + const auto result = value->evaluate(expression::EvaluationContext({}, nullptr, {rampEvaluationParameter})); + return *expression::fromExpressionValue(*result); + } + + bool isDataDriven() const { return false; } + bool hasDataDrivenPropertyDifference(const ColorRampPropertyValue&) const { return false; } + + const expression::Expression& getExpression() const { return *value; } +}; + + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/conversion/color_ramp_property_value.hpp b/include/mbgl/style/conversion/color_ramp_property_value.hpp new file mode 100644 index 0000000000..cf5d5e55d9 --- /dev/null +++ b/include/mbgl/style/conversion/color_ramp_property_value.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +struct Converter { + optional operator()(const Convertible& value, Error& error) const { + using namespace mbgl::style::expression; + if (isUndefined(value)) { + return ColorRampPropertyValue(); + } else if (isExpression(value)) { + ParsingContext ctx(type::Color); + ParseResult expression = ctx.parseLayerPropertyExpression(value); + if (!expression) { + error = { ctx.getCombinedErrors() }; + return {}; + } + assert(*expression); + if (!isFeatureConstant(**expression)) { + error = { "property expressions not supported" }; + return {}; + } + if (!isZoomConstant(**expression)) { + error = { "zoom expressions not supported" }; + return {}; + } + return {ColorRampPropertyValue(std::move(*expression))}; + } else { + error = { "color ramp must be an expression" }; + return {}; + } + } +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/conversion/heatmap_color_property_value.hpp b/include/mbgl/style/conversion/heatmap_color_property_value.hpp deleted file mode 100644 index a4710792d2..0000000000 --- a/include/mbgl/style/conversion/heatmap_color_property_value.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace mbgl { -namespace style { -namespace conversion { - -template <> -struct Converter { - optional operator()(const Convertible& value, Error& error) const { - using namespace mbgl::style::expression; - if (isUndefined(value)) { - return HeatmapColorPropertyValue(); - } else if (isExpression(value)) { - ParsingContext ctx(type::Color); - ParseResult expression = ctx.parseLayerPropertyExpression(value); - if (!expression) { - error = { ctx.getCombinedErrors() }; - return {}; - } - assert(*expression); - if (!isFeatureConstant(**expression)) { - error = { "property expressions not supported" }; - return {}; - } - if (!isZoomConstant(**expression)) { - error = { "zoom expressions not supported" }; - return {}; - } - return {HeatmapColorPropertyValue(std::move(*expression))}; - } else { - error = { "heatmap-color must be an expression" }; - return {}; - } - } -}; - -} // namespace conversion -} // namespace style -} // namespace mbgl diff --git a/include/mbgl/style/heatmap_color_property_value.hpp b/include/mbgl/style/heatmap_color_property_value.hpp deleted file mode 100644 index 130639c6e2..0000000000 --- a/include/mbgl/style/heatmap_color_property_value.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace mbgl { -namespace style { - -/* - * Special-case implementation of (a subset of) the PropertyValue interface - * used for building the HeatmapColor paint property traits class. - */ -class HeatmapColorPropertyValue { -private: - std::shared_ptr value; - - friend bool operator==(const HeatmapColorPropertyValue& lhs, const HeatmapColorPropertyValue& rhs) { - return (lhs.isUndefined() && rhs.isUndefined()) || (lhs.value && rhs.value && *(lhs.value) == *(rhs.value)); - } - - friend bool operator!=(const HeatmapColorPropertyValue& lhs, const HeatmapColorPropertyValue& rhs) { - return !(lhs == rhs); - } - -public: - HeatmapColorPropertyValue() : value(nullptr) {} - HeatmapColorPropertyValue(std::shared_ptr value_) : value(std::move(value_)) {} - - bool isUndefined() const { return value.get() == nullptr; } - - // noop, needed for batch evaluation of paint property values to compile - template - Color evaluate(const Evaluator&, TimePoint = {}) const { return {}; } - - Color evaluate(double heatmapDensity) const { - const auto result = value->evaluate(expression::EvaluationContext({}, nullptr, {heatmapDensity})); - return *expression::fromExpressionValue(*result); - } - - bool isDataDriven() const { return false; } - bool hasDataDrivenPropertyDifference(const HeatmapColorPropertyValue&) const { return false; } - - const expression::Expression& getExpression() const { return *value; } -}; - - -} // namespace style -} // namespace mbgl diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp index 33d927ad38..4c434b2aff 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -2,11 +2,11 @@ #pragma once +#include #include #include #include #include -#include #include @@ -55,9 +55,9 @@ public: void setHeatmapIntensityTransition(const TransitionOptions&); TransitionOptions getHeatmapIntensityTransition() const; - static HeatmapColorPropertyValue getDefaultHeatmapColor(); - HeatmapColorPropertyValue getHeatmapColor() const; - void setHeatmapColor(HeatmapColorPropertyValue); + static ColorRampPropertyValue getDefaultHeatmapColor(); + ColorRampPropertyValue getHeatmapColor() const; + void setHeatmapColor(ColorRampPropertyValue); void setHeatmapColorTransition(const TransitionOptions&); TransitionOptions getHeatmapColorTransition() const; diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index 6d40405ccd..e15ff74f17 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -7,13 +7,13 @@ #pragma once +<% if (type === 'heatmap') { -%> +#include +<% } -%> #include #include #include #include -<% if (type === 'heatmap') { -%> -#include -<% } -%> #include -- cgit v1.2.1