blob: 50f2b48453cc7439482e0f185dd04ed8ce9de2c1 (
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
|
#pragma once
#include <mbgl/util/feature.hpp>
#include <map>
namespace mbgl {
namespace style {
template <class T>
class IntervalStops {
public:
using Stops = std::map<float, T>;
Stops stops;
IntervalStops() = default;
IntervalStops(Stops stops_)
: stops(std::move(stops_)) {
}
optional<T> evaluate(const Value& value) const {
if (stops.empty()) {
assert(false);
return {};
}
optional<float> z = numericValue<float>(value);
if (!z) {
return {};
}
auto it = stops.upper_bound(*z);
if (it == stops.end()) {
return stops.rbegin()->second;
} else if (it == stops.begin()) {
return stops.begin()->second;
} else {
return std::prev(it)->second;
}
}
friend bool operator==(const IntervalStops& lhs,
const IntervalStops& rhs) {
return lhs.stops == rhs.stops;
}
};
} // namespace style
} // namespace mbgl
|