1 | #pragma once |
2 | |
3 | #include <mbgl/util/interpolate.hpp> |
4 | #include <mbgl/util/range.hpp> |
5 | #include <mbgl/util/unitbezier.hpp> |
6 | |
7 | namespace mbgl { |
8 | namespace style { |
9 | namespace expression { |
10 | |
11 | class ExponentialInterpolator { |
12 | public: |
13 | ExponentialInterpolator(double base_) : base(base_) {} |
14 | |
15 | double base; |
16 | |
17 | double interpolationFactor(const Range<double>& inputLevels, const double input) const { |
18 | return util::interpolationFactor(base, |
19 | range: Range<float> { |
20 | static_cast<float>(inputLevels.min), |
21 | static_cast<float>(inputLevels.max) |
22 | }, |
23 | z: input); |
24 | } |
25 | |
26 | bool operator==(const ExponentialInterpolator& rhs) const { |
27 | return base == rhs.base; |
28 | } |
29 | }; |
30 | |
31 | class CubicBezierInterpolator { |
32 | public: |
33 | CubicBezierInterpolator(double x1_, double y1_, double x2_, double y2_) : ub(x1_, y1_, x2_, y2_) {} |
34 | |
35 | double interpolationFactor(const Range<double>& inputLevels, const double input) const { |
36 | return ub.solve(x: input / (inputLevels.max - inputLevels.min), epsilon: 1e-6); |
37 | } |
38 | |
39 | bool operator==(const CubicBezierInterpolator& rhs) const { |
40 | return ub == rhs.ub; |
41 | } |
42 | |
43 | util::UnitBezier ub; |
44 | }; |
45 | |
46 | using Interpolator = variant<ExponentialInterpolator, CubicBezierInterpolator>; |
47 | |
48 | } // namespace expression |
49 | } // namespace style |
50 | } // namespace mbgl |
51 | |