diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-07-04 23:12:58 +0300 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-07-05 15:11:14 +0300 |
commit | 514485502db8ecacf2b11abad4599d7af09b0cf8 (patch) | |
tree | 21a76d2fda8b5ec5e19624f5eedf609a545b59b4 /include/mbgl/style/color_ramp_property_value.hpp | |
parent | 32dce870d756063167e000302afb553714f1f0cb (diff) | |
download | qtlocation-mapboxgl-514485502db8ecacf2b11abad4599d7af09b0cf8.tar.gz |
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.
Diffstat (limited to 'include/mbgl/style/color_ramp_property_value.hpp')
-rw-r--r-- | include/mbgl/style/color_ramp_property_value.hpp | 49 |
1 files changed, 49 insertions, 0 deletions
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 <mbgl/util/variant.hpp> +#include <mbgl/style/undefined.hpp> +#include <mbgl/style/function/camera_function.hpp> + +namespace mbgl { +namespace style { + +/* + * Special-case implementation of (a subset of) the PropertyValue<T> interface + * used for building the HeatmapColor paint property traits class. + */ +class ColorRampPropertyValue { +private: + std::shared_ptr<expression::Expression> 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<expression::Expression> value_) : value(std::move(value_)) {} + + bool isUndefined() const { return value.get() == nullptr; } + + // noop, needed for batch evaluation of paint property values to compile + template <typename Evaluator> + Color evaluate(const Evaluator&, TimePoint = {}) const { return {}; } + + Color evaluate(double rampEvaluationParameter) const { + const auto result = value->evaluate(expression::EvaluationContext({}, nullptr, {rampEvaluationParameter})); + return *expression::fromExpressionValue<Color>(*result); + } + + bool isDataDriven() const { return false; } + bool hasDataDrivenPropertyDifference(const ColorRampPropertyValue&) const { return false; } + + const expression::Expression& getExpression() const { return *value; } +}; + + +} // namespace style +} // namespace mbgl |