1 #include <mbgl/style/expression/get_covering_stops.hpp>
2
3 namespace mbgl {
4 namespace style {
5 namespace expression {
6
getCoveringStops(const std::map<double,std::unique_ptr<Expression>> & stops,const double lower,const double upper)7 Range<float> getCoveringStops(const std::map<double, std::unique_ptr<Expression>>& stops,
8 const double lower, const double upper) {
9 assert(!stops.empty());
10 auto minIt = stops.lower_bound(lower);
11 auto maxIt = stops.lower_bound(upper);
12
13 // lower_bound yields first element >= lowerZoom, but we want the *last*
14 // element <= lowerZoom, so if we found a stop > lowerZoom, back up by one.
15 if (minIt != stops.begin() && minIt != stops.end() && minIt->first > lower) {
16 minIt--;
17 }
18 return Range<float> {
19 static_cast<float>(minIt == stops.end() ? stops.rbegin()->first : minIt->first),
20 static_cast<float>(maxIt == stops.end() ? stops.rbegin()->first : maxIt->first)
21 };
22 }
23
24 } // namespace expression
25 } // namespace style
26 } // namespace mbgl
27