summaryrefslogtreecommitdiff
path: root/include/mbgl/style/function/exponential_stops.hpp
diff options
context:
space:
mode:
authorJesse Crocker <jesse@gaiagps.com>2017-03-01 11:15:11 -0700
committerJesse Crocker <jesse@gaiagps.com>2017-03-01 11:15:11 -0700
commit9e8dc9a9e3e86adb9987ae69766cc42c7d9efece (patch)
treef5f0abd4d342c89ad0405d01969f9d6caecc1c90 /include/mbgl/style/function/exponential_stops.hpp
parent16fb0672e64a72b7400c321d55858b73cd5d8c3f (diff)
parentf28d75dccd9bf4a7615df87faccc5cf5eff8df89 (diff)
downloadqtlocation-mapboxgl-9e8dc9a9e3e86adb9987ae69766cc42c7d9efece.tar.gz
Merge remote-tracking branch 'origin/master' into feature/custom-vector-source
Diffstat (limited to 'include/mbgl/style/function/exponential_stops.hpp')
-rw-r--r--include/mbgl/style/function/exponential_stops.hpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/include/mbgl/style/function/exponential_stops.hpp b/include/mbgl/style/function/exponential_stops.hpp
new file mode 100644
index 0000000000..051f5aa9aa
--- /dev/null
+++ b/include/mbgl/style/function/exponential_stops.hpp
@@ -0,0 +1,54 @@
+#pragma once
+
+#include <mbgl/util/feature.hpp>
+#include <mbgl/util/interpolate.hpp>
+
+#include <map>
+
+namespace mbgl {
+namespace style {
+
+template <class T>
+class ExponentialStops {
+public:
+ using Stops = std::map<float, T>;
+
+ Stops stops;
+ float base = 1.0f;
+
+ ExponentialStops() = default;
+ ExponentialStops(Stops stops_, float base_ = 1.0f)
+ : stops(std::move(stops_)),
+ base(base_) {
+ }
+
+ optional<T> evaluate(const Value& value) const {
+ if (stops.empty()) {
+ assert(false);
+ return T();
+ }
+
+ optional<float> z = numericValue<float>(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