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
67
68
69
70
71
72
73
74
75
76
77
78
|
#include <mbgl/util/transition.hpp>
#include <mbgl/util/unitbezier.hpp>
#include <mbgl/platform/platform.hpp>
namespace mbgl { namespace util {
UnitBezier ease(0, 0, 0.25, 1);
transition::~transition() {}
double transition::interpolateDouble(double from, double to, double t) const {
return from + (to - from) * t;
}
float transition::interpolateFloat(float from, float to, double t) const {
return from + (to - from) * (float)t;
}
mbgl::Color transition::interpolateColor(mbgl::Color from, mbgl::Color to, double t) const {
return {{ interpolateFloat(from[0], to[0], t),
interpolateFloat(from[1], to[1], t),
interpolateFloat(from[2], to[2], t),
interpolateFloat(from[3], to[3], t) }};
}
std::array<float, 2> transition::interpolateFloatArray(std::array<float, 2> from, std::array<float, 2> to, double t) const {
return {{ interpolateFloat(from[0], to[0], t), interpolateFloat(from[1], to[1], t) }};
}
template <>
transition::state ease_transition<double>::update(timestamp now) const {
float t = progress(now);
if (t >= 1) {
value = to;
return complete;
} else {
value = interpolateDouble(from, to, ease.solve(t, 0.001));
return running;
}
}
template <>
transition::state ease_transition<mbgl::Color>::update(timestamp now) const {
float t = progress(now);
if (t >= 1) {
value = to;
return complete;
} else {
value = interpolateColor(from, to, ease.solve(t, 0.001));
return running;
}
}
template <>
transition::state ease_transition<float>::update(timestamp now) const {
float t = progress(now);
if (t >= 1) {
value = to;
return complete;
} else {
value = interpolateFloat(from, to, ease.solve(t, 0.001));
return running;
}
}
template <>
transition::state ease_transition<std::array<float, 2>>::update(timestamp now) const {
float t = progress(now);
if (t >= 1) {
value = to;
return complete;
} else {
value = interpolateFloatArray(from, to, ease.solve(t, 0.001));
return running;
}
}
}}
|