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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
#include <mbgl/test/util.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/renderer/property_evaluator.hpp>
#include <mbgl/renderer/data_driven_property_evaluator.hpp>
using namespace mbgl;
using namespace mbgl::style;
using namespace std::literals::chrono_literals;
float evaluate(Transitioning<PropertyValue<float>>& property, Duration delta = Duration::zero()) {
ZoomHistory zoomHistory;
zoomHistory.update(0, TimePoint::min() + delta);
PropertyEvaluationParameters parameters {
zoomHistory,
TimePoint::min() + delta,
Duration::zero()
};
PropertyEvaluator<float> evaluator {
parameters,
0.0f
};
return property.evaluate(evaluator, parameters.now);
}
PossiblyEvaluatedPropertyValue<float> evaluate(Transitioning<DataDrivenPropertyValue<float>>& property, Duration delta = Duration::zero()) {
ZoomHistory zoomHistory;
zoomHistory.update(0, TimePoint::min() + delta);
PropertyEvaluationParameters parameters {
zoomHistory,
TimePoint::min() + delta,
Duration::zero()
};
DataDrivenPropertyEvaluator<float> evaluator {
parameters,
0.0f
};
return property.evaluate(evaluator, parameters.now);
}
TEST(TransitioningPropertyValue, EvaluateDefaultValue) {
Transitioning<PropertyValue<float>> property;
ASSERT_EQ(0.0f, evaluate(property));
}
TEST(TransitioningPropertyValue, EvaluateUntransitionedConstant) {
Transitioning<PropertyValue<float>> property {
PropertyValue<float>(1.0f),
Transitioning<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
ASSERT_EQ(1.0f, evaluate(property));
}
TEST(TransitioningPropertyValue, EvaluateTransitionedConstantWithoutDelay) {
TransitionOptions transition;
transition.duration = { 1000ms };
Transitioning<PropertyValue<float>> t0 {
PropertyValue<float>(0.0f),
Transitioning<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
Transitioning<PropertyValue<float>> t1 {
PropertyValue<float>(1.0f),
t0,
transition,
TimePoint::min()
};
ASSERT_FLOAT_EQ(0.0f, evaluate(t1, 0ms));
ASSERT_FLOAT_EQ(0.823099f, evaluate(t1, 500ms));
ASSERT_FLOAT_EQ(1.0f, evaluate(t1, 1500ms));
}
TEST(TransitioningPropertyValue, EvaluateTransitionedConstantWithDelay) {
TransitionOptions transition;
transition.delay = { 1000ms };
transition.duration = { 1000ms };
Transitioning<PropertyValue<float>> t0 {
PropertyValue<float>(0.0f),
Transitioning<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
Transitioning<PropertyValue<float>> t1 {
PropertyValue<float>(1.0f),
t0,
transition,
TimePoint::min()
};
ASSERT_FLOAT_EQ(0.0f, evaluate(t1, 0ms));
ASSERT_FLOAT_EQ(0.0f, evaluate(t1, 500ms));
ASSERT_FLOAT_EQ(0.0f, evaluate(t1, 612ms));
ASSERT_FLOAT_EQ(0.823099f, evaluate(t1, 1500ms));
ASSERT_FLOAT_EQ(1.0f, evaluate(t1, 2500ms));
}
TEST(TransitioningDataDrivenPropertyValue, Evaluate) {
TransitionOptions transition;
transition.delay = { 1000ms };
transition.duration = { 1000ms };
Transitioning<DataDrivenPropertyValue<float>> t0 {
DataDrivenPropertyValue<float>(0.0f),
Transitioning<DataDrivenPropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
SourceFunction<float> sourceFunction = {
"property_name",
IdentityStops<float>()
};
Transitioning<DataDrivenPropertyValue<float>> t1 {
DataDrivenPropertyValue<float>(sourceFunction),
t0,
transition,
TimePoint::min()
};
ASSERT_TRUE(evaluate(t0, 0ms).isConstant());
ASSERT_FALSE(evaluate(t1, 0ms).isConstant()) <<
"A paint property transition to a data-driven evaluates immediately to the final value (see https://github.com/mapbox/mapbox-gl-native/issues/8237).";
}
|