From 141e995806576364d185626176c1b993fc519291 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 28 Oct 2016 16:39:50 -0700 Subject: [core] Add support for data-driven styling --- include/mbgl/style/function/exponential_stops.hpp | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 include/mbgl/style/function/exponential_stops.hpp (limited to 'include/mbgl/style/function/exponential_stops.hpp') diff --git a/include/mbgl/style/function/exponential_stops.hpp b/include/mbgl/style/function/exponential_stops.hpp new file mode 100644 index 0000000000..7bd8783614 --- /dev/null +++ b/include/mbgl/style/function/exponential_stops.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include +#include + +#include + +namespace mbgl { +namespace style { + +template +class ExponentialStops { +public: + using Stops = std::map; + + Stops stops; + float base = 1.0f; + + ExponentialStops() = default; + ExponentialStops(Stops stops_, float base_ = 1.0f) + : stops(std::move(stops_)), + base(base_) { + } + + T evaluate(const Value& value) const { + if (stops.empty()) { + assert(false); + return T(); + } + + optional z = numericValue(value); + if (!z) { + return T(); + } + + 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 util::interpolate(std::prev(it)->second, it->second, + util::interpolationFactor(base, { std::prev(it)->first, it->first }, *z)); + } + } + + friend bool operator==(const ExponentialStops& lhs, + const ExponentialStops& rhs) { + return lhs.stops == rhs.stops && lhs.base == rhs.base; + } +}; + +} // namespace style +} // namespace mbgl -- cgit v1.2.1