summaryrefslogtreecommitdiff
path: root/src/mbgl/style/property_evaluator.hpp
blob: a0bce2f49990ea42cfa74c4e3f25bdcd8f0dbc9b (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
63
64
65
66
#pragma once

#include <mbgl/style/property_value.hpp>
#include <mbgl/util/interpolate.hpp>

namespace mbgl {
namespace style {

class CalculationParameters;

template <typename T>
class PropertyEvaluator {
public:
    using ResultType = T;

    PropertyEvaluator(const CalculationParameters& parameters_, T defaultValue_)
        : parameters(parameters_),
          defaultValue(std::move(defaultValue_)) {}

    T operator()(const Undefined&) const { return defaultValue; }
    T operator()(const T& constant) const { return constant; }
    T operator()(const Function<T>&) const;

private:
    const CalculationParameters& parameters;
    T defaultValue;
};

template <typename T>
struct Faded {
    T from;
    T to;
    float fromScale;
    float toScale;
    float t;
};

template <typename T>
class CrossFadedPropertyEvaluator {
public:
    using ResultType = Faded<T>;

    CrossFadedPropertyEvaluator(const CalculationParameters& parameters_, T defaultValue_)
        : parameters(parameters_),
          defaultValue(std::move(defaultValue_)) {}

    Faded<T> operator()(const Undefined&) const;
    Faded<T> operator()(const T& constant) const;
    Faded<T> operator()(const Function<T>&) const;

private:
    Faded<T> calculate(const T& min, const T& mid, const T& max) const;

    const CalculationParameters& parameters;
    T defaultValue;
};

} // namespace style

namespace util {
template <typename T>
struct Interpolator<style::Faded<T>>
    : Uninterpolated {};
} // namespace util

} // namespace mbgl