summaryrefslogtreecommitdiff
path: root/include/mbgl/style
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-05-19 09:39:41 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-05-19 11:48:45 -0700
commitbdff99c853431b89b56ac9a71dc73a65bc5515df (patch)
tree5ff632155d0b107566b745265330515dabfb2b8a /include/mbgl/style
parent895275d6fcba6e2181a2e836f274db7c12ee4f75 (diff)
downloadqtlocation-mapboxgl-bdff99c853431b89b56ac9a71dc73a65bc5515df.tar.gz
[core] Eliminate round-trip through Value in CameraFunction::evaluate
Diffstat (limited to 'include/mbgl/style')
-rw-r--r--include/mbgl/style/function/camera_function.hpp2
-rw-r--r--include/mbgl/style/function/exponential_stops.hpp19
-rw-r--r--include/mbgl/style/function/interval_stops.hpp17
3 files changed, 22 insertions, 16 deletions
diff --git a/include/mbgl/style/function/camera_function.hpp b/include/mbgl/style/function/camera_function.hpp
index 2e4aac2238..1b03cc8cf6 100644
--- a/include/mbgl/style/function/camera_function.hpp
+++ b/include/mbgl/style/function/camera_function.hpp
@@ -25,7 +25,7 @@ public:
T evaluate(float zoom) const {
return stops.match([&] (const auto& s) {
- return s.evaluate(Value(double(zoom))).value_or(T());
+ return s.evaluate(zoom).value_or(T());
});
}
diff --git a/include/mbgl/style/function/exponential_stops.hpp b/include/mbgl/style/function/exponential_stops.hpp
index 051f5aa9aa..1c57ec6f5d 100644
--- a/include/mbgl/style/function/exponential_stops.hpp
+++ b/include/mbgl/style/function/exponential_stops.hpp
@@ -22,26 +22,29 @@ public:
base(base_) {
}
- optional<T> evaluate(const Value& value) const {
+ optional<T> evaluate(float z) const {
if (stops.empty()) {
assert(false);
return T();
}
- optional<float> z = numericValue<float>(value);
- if (!z) {
- return T();
- }
-
- auto it = stops.upper_bound(*z);
+ 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));
+ util::interpolationFactor(base, { std::prev(it)->first, it->first }, z));
+ }
+ }
+
+ optional<T> evaluate(const Value& value) const {
+ optional<float> z = numericValue<float>(value);
+ if (!z) {
+ return T();
}
+ return evaluate(*z);
}
friend bool operator==(const ExponentialStops& lhs,
diff --git a/include/mbgl/style/function/interval_stops.hpp b/include/mbgl/style/function/interval_stops.hpp
index 50f2b48453..a482a6081c 100644
--- a/include/mbgl/style/function/interval_stops.hpp
+++ b/include/mbgl/style/function/interval_stops.hpp
@@ -18,18 +18,13 @@ public:
: stops(std::move(stops_)) {
}
- optional<T> evaluate(const Value& value) const {
+ optional<T> evaluate(float z) const {
if (stops.empty()) {
assert(false);
return {};
}
- optional<float> z = numericValue<float>(value);
- if (!z) {
- return {};
- }
-
- auto it = stops.upper_bound(*z);
+ auto it = stops.upper_bound(z);
if (it == stops.end()) {
return stops.rbegin()->second;
} else if (it == stops.begin()) {
@@ -39,6 +34,14 @@ public:
}
}
+ optional<T> evaluate(const Value& value) const {
+ optional<float> z = numericValue<float>(value);
+ if (!z) {
+ return {};
+ }
+ return evaluate(*z);
+ }
+
friend bool operator==(const IntervalStops& lhs,
const IntervalStops& rhs) {
return lhs.stops == rhs.stops;