summaryrefslogtreecommitdiff
path: root/src/mbgl/style/property_expression.cpp
blob: 8d603e4b153d6c2f527c2099c5bdde4e486c8940 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#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);
    isRuntimeConstant_ = expression::isRuntimeConstant(*expression);
}

bool PropertyExpressionBase::isZoomConstant() const noexcept {
    return isZoomConstant_;
}

bool PropertyExpressionBase::isFeatureConstant() const noexcept {
    return isFeatureConstant_;
}

bool PropertyExpressionBase::isRuntimeConstant() const noexcept {
    return isRuntimeConstant_;
}

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;
}

std::shared_ptr<const expression::Expression> PropertyExpressionBase::getSharedExpression() const noexcept {
    return expression;
}

} // namespace style
} // namespace mbgl