summaryrefslogtreecommitdiff
path: root/include/mbgl/style/function
diff options
context:
space:
mode:
Diffstat (limited to 'include/mbgl/style/function')
-rw-r--r--include/mbgl/style/function/camera_function.hpp5
-rw-r--r--include/mbgl/style/function/composite_function.hpp7
-rw-r--r--include/mbgl/style/function/exponential_stops.hpp22
-rw-r--r--include/mbgl/style/function/interval_stops.hpp18
-rw-r--r--include/mbgl/style/function/source_function.hpp3
5 files changed, 31 insertions, 24 deletions
diff --git a/include/mbgl/style/function/camera_function.hpp b/include/mbgl/style/function/camera_function.hpp
index 2e4aac2238..7fde365b3d 100644
--- a/include/mbgl/style/function/camera_function.hpp
+++ b/include/mbgl/style/function/camera_function.hpp
@@ -12,7 +12,7 @@ template <class T>
class CameraFunction {
public:
using Stops = std::conditional_t<
- util::Interpolatable<T>,
+ util::Interpolatable<T>::value,
variant<
ExponentialStops<T>,
IntervalStops<T>>,
@@ -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());
});
}
@@ -35,6 +35,7 @@ public:
}
Stops stops;
+ bool useIntegerZoom = false;
};
} // namespace style
diff --git a/include/mbgl/style/function/composite_function.hpp b/include/mbgl/style/function/composite_function.hpp
index b82e63bc37..7b524b6021 100644
--- a/include/mbgl/style/function/composite_function.hpp
+++ b/include/mbgl/style/function/composite_function.hpp
@@ -24,7 +24,7 @@ template <class T>
class CompositeFunction {
public:
using InnerStops = std::conditional_t<
- util::Interpolatable<T>,
+ util::Interpolatable<T>::value,
variant<
ExponentialStops<T>,
IntervalStops<T>,
@@ -34,7 +34,7 @@ public:
CategoricalStops<T>>>;
using Stops = std::conditional_t<
- util::Interpolatable<T>,
+ util::Interpolatable<T>::value,
variant<
CompositeExponentialStops<T>,
CompositeIntervalStops<T>,
@@ -67,7 +67,7 @@ public:
// lower_bound yields first element >= zoom, but we want the *last*
// element <= zoom, so if we found a stop > zoom, back up by one.
- if (minIt != s.stops.begin() && minIt->first > zoom) {
+ if (minIt != s.stops.begin() && minIt != s.stops.end() && minIt->first > zoom) {
minIt--;
}
@@ -135,6 +135,7 @@ public:
std::string property;
Stops stops;
optional<T> defaultValue;
+ bool useIntegerZoom = false;
private:
T evaluateFinal(const CoveringRanges& ranges, const Value& value, T finalDefaultValue) const {
diff --git a/include/mbgl/style/function/exponential_stops.hpp b/include/mbgl/style/function/exponential_stops.hpp
index 051f5aa9aa..b3866c4059 100644
--- a/include/mbgl/style/function/exponential_stops.hpp
+++ b/include/mbgl/style/function/exponential_stops.hpp
@@ -22,26 +22,28 @@ 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();
+ 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()) {
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 {};
}
+ 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..45e2dc6f2e 100644
--- a/include/mbgl/style/function/interval_stops.hpp
+++ b/include/mbgl/style/function/interval_stops.hpp
@@ -18,18 +18,12 @@ 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 +33,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;
diff --git a/include/mbgl/style/function/source_function.hpp b/include/mbgl/style/function/source_function.hpp
index f6601d9ea3..9c2ad101ec 100644
--- a/include/mbgl/style/function/source_function.hpp
+++ b/include/mbgl/style/function/source_function.hpp
@@ -16,7 +16,7 @@ template <class T>
class SourceFunction {
public:
using Stops = std::conditional_t<
- util::Interpolatable<T>,
+ util::Interpolatable<T>::value,
variant<
ExponentialStops<T>,
IntervalStops<T>,
@@ -53,6 +53,7 @@ public:
std::string property;
Stops stops;
optional<T> defaultValue;
+ bool useIntegerZoom = false;
};
} // namespace style