summaryrefslogtreecommitdiff
path: root/src/mbgl/style/property_expression.cpp
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-03-11 10:26:19 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-03-13 17:14:53 +0200
commit8be135231d9efe41a3b12037518d02b36104e8cf (patch)
treeefecd5380232f899aed2cd5824dc16f057f0469a /src/mbgl/style/property_expression.cpp
parent8a51362bccbd6487dd1ed8518443b16ba6114fd8 (diff)
downloadqtlocation-mapboxgl-8be135231d9efe41a3b12037518d02b36104e8cf.tar.gz
[core] Add possibility of overriding paint properties inside format expression #14062
* [core] Add format override expression and formatted section to evaluation context * [core] Add textColor to TaggedString's formatted section * [core] Add FormatSectionOverrides and introduce overridable properties * [core] Populate symbol layer paint properties for text sections * [core] Add benchmark for style that uses text-color override * [core] Add unit test for FormatOverrideExpression * [core] Add unit test for FormatSectionOverrides
Diffstat (limited to 'src/mbgl/style/property_expression.cpp')
-rw-r--r--src/mbgl/style/property_expression.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/mbgl/style/property_expression.cpp b/src/mbgl/style/property_expression.cpp
new file mode 100644
index 0000000000..9ebecc4b40
--- /dev/null
+++ b/src/mbgl/style/property_expression.cpp
@@ -0,0 +1,68 @@
+#include <mbgl/style/property_expression.hpp>
+
+namespace mbgl {
+namespace style {
+
+PropertyExpressionBase::PropertyExpressionBase(std::unique_ptr<expression::Expression> expression_)
+ : expression(std::move(expression_)),
+ zoomCurve(expression::findZoomCurveChecked(expression.get())) {
+ isZoomConstant_ = expression::isZoomConstant(*expression);
+ isFeatureConstant_ = expression::isFeatureConstant(*expression);
+}
+
+bool PropertyExpressionBase::isZoomConstant() const noexcept {
+ return isZoomConstant_;
+}
+
+bool PropertyExpressionBase::isFeatureConstant() const noexcept {
+ return isFeatureConstant_;
+}
+
+bool PropertyExpressionBase::canEvaluateWith(const expression::EvaluationContext& context) const noexcept {
+ if (context.zoom) {
+ if (context.feature != nullptr) {
+ return !isFeatureConstant();
+ }
+ return !isZoomConstant() && isFeatureConstant();
+ }
+
+ if (context.feature != nullptr) {
+ return isZoomConstant() && !isFeatureConstant();
+ }
+
+ return true;
+}
+
+float PropertyExpressionBase::interpolationFactor(const Range<float>& inputLevels, const float inputValue) const noexcept {
+ return zoomCurve.match(
+ [](std::nullptr_t) {
+ assert(false);
+ return 0.0f;
+ },
+ [&](const expression::Interpolate* z) {
+ return z->interpolationFactor(Range<double> { inputLevels.min, inputLevels.max }, inputValue);
+ },
+ [](const expression::Step*) {
+ return 0.0f;
+ }
+ );
+}
+
+Range<float> PropertyExpressionBase::getCoveringStops(const float lower, const float upper) const noexcept {
+ return zoomCurve.match(
+ [](std::nullptr_t) {
+ assert(false);
+ return Range<float>(0.0f, 0.0f);
+ },
+ [&](auto z) {
+ return z->getCoveringStops(lower, upper);
+ }
+ );
+}
+
+const expression::Expression& PropertyExpressionBase::getExpression() const noexcept {
+ return *expression;
+}
+
+} // namespace style
+} // namespace mbgl