#pragma once #include #include #include #include #include #include #include #include namespace mbgl { class GeometryTileFeature; namespace style { // A CompositeFunction consists of an outer zoom function whose stop range values are // "inner" source functions. It provides the GL Native implementation of // "zoom-and-property" functions from the style spec. template class CompositeFunction { public: using InnerStops = std::conditional_t< util::Interpolatable, variant< ExponentialStops, IntervalStops, CategoricalStops>, variant< IntervalStops, CategoricalStops>>; using Stops = std::conditional_t< util::Interpolatable, variant< std::map>, std::map>, std::map>>, variant< std::map>, std::map>>>; CompositeFunction(std::string property_, Stops stops_) : property(std::move(property_)), stops(std::move(stops_)) { } std::tuple, Range> coveringRanges(float zoom) const { return stops.match( [&] (const auto& s) { assert(!s.empty()); auto minIt = s.lower_bound(zoom); auto maxIt = s.upper_bound(zoom); if (minIt != s.begin()) { minIt--; } return std::make_tuple( Range { minIt == s.end() ? s.rbegin()->first : minIt->first, maxIt == s.end() ? s.rbegin()->first : maxIt->first }, Range { minIt == s.end() ? s.rbegin()->second : minIt->second, maxIt == s.end() ? s.rbegin()->second : maxIt->second } ); } ); } Range evaluate(Range coveringStops, const GeometryTileFeature& feature) const { optional v = feature.getValue(property); if (!v) { return { T(), T() }; } auto eval = [&] (const auto& s) { return s.evaluate(*v); }; return Range { coveringStops.min.match(eval), coveringStops.max.match(eval) }; } T evaluate(float zoom, const GeometryTileFeature& feature) const { std::tuple, Range> ranges = coveringRanges(zoom); Range resultRange = evaluate(std::get<1>(ranges), feature); return util::interpolate( resultRange.min, resultRange.max, util::interpolationFactor(1.0f, std::get<0>(ranges), zoom)); } friend bool operator==(const CompositeFunction& lhs, const CompositeFunction& rhs) { return lhs.property == rhs.property && lhs.stops == rhs.stops; } std::string property; Stops stops; }; } // namespace style } // namespace mbgl