summaryrefslogtreecommitdiff
path: root/include/mbgl/style/expression/interpolator.hpp
blob: 62b48c1752b2b5562cd14cda644f29fa94ee71d3 (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
#pragma once

#include <mbgl/util/interpolate.hpp>
#include <mbgl/util/range.hpp>
#include <mbgl/util/unitbezier.hpp>

namespace mbgl {
namespace style {
namespace expression {

class ExponentialInterpolator {
public:
    ExponentialInterpolator(double base_) : base(base_) {}

    double base;
    
    double interpolationFactor(const Range<double>& inputLevels, const double input) const {
        return util::interpolationFactor(base,
                                         Range<float> {
                                            static_cast<float>(inputLevels.min),
                                            static_cast<float>(inputLevels.max)
                                         },
                                         input);
    }
    
    bool operator==(const ExponentialInterpolator& rhs) const {
        return base == rhs.base;
    }
};

class CubicBezierInterpolator {
public:
    CubicBezierInterpolator(double x1_, double y1_, double x2_, double y2_) : ub(x1_, y1_, x2_, y2_) {}
    
    double interpolationFactor(const Range<double>& inputLevels, const double input) const {
        return ub.solve(util::interpolationFactor(1.0,
                                                  Range<float> {
                                                      static_cast<float>(inputLevels.min),
                                                      static_cast<float>(inputLevels.max)
                                                  },
                                                  input),
                        1e-6);
    }
    
    bool operator==(const CubicBezierInterpolator& rhs) const {
        return ub == rhs.ub;
    }
    
    util::UnitBezier ub;
};

using Interpolator = variant<ExponentialInterpolator, CubicBezierInterpolator>;

} // namespace expression
} // namespace style
} // namespace mbgl