summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-01-10 11:48:06 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-01-10 13:45:00 -0800
commitcedda5ef4f73fccfc795e6bc48b368e48f11ad8d (patch)
treef695cb615da4e023017d44fad8ded4259efab0fd /src
parentecbb0baf60138cea2c72ec4e75b788ca59d86e14 (diff)
downloadqtlocation-mapboxgl-cedda5ef4f73fccfc795e6bc48b368e48f11ad8d.tar.gz
[core] Handle NaN input to interpolate and step
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/expression/step.cpp9
-rw-r--r--src/mbgl/style/expression/value.cpp10
2 files changed, 11 insertions, 8 deletions
diff --git a/src/mbgl/style/expression/step.cpp b/src/mbgl/style/expression/step.cpp
index bfcb6fd270..11bf543b76 100644
--- a/src/mbgl/style/expression/step.cpp
+++ b/src/mbgl/style/expression/step.cpp
@@ -2,6 +2,7 @@
#include <mbgl/style/expression/get_covering_stops.hpp>
#include <mbgl/util/string.hpp>
+#include <cmath>
namespace mbgl {
namespace style {
@@ -9,8 +10,14 @@ namespace expression {
EvaluationResult Step::evaluate(const EvaluationContext& params) const {
const EvaluationResult evaluatedInput = input->evaluate(params);
- if (!evaluatedInput) { return evaluatedInput.error(); }
+ if (!evaluatedInput) {
+ return evaluatedInput.error();
+ }
+
float x = *fromExpressionValue<float>(*evaluatedInput);
+ if (std::isnan(x)) {
+ return EvaluationError { "Input is not a number." };
+ }
if (stops.empty()) {
return EvaluationError { "No stops in step curve." };
diff --git a/src/mbgl/style/expression/value.cpp b/src/mbgl/style/expression/value.cpp
index b75f471ce3..ef4769df02 100644
--- a/src/mbgl/style/expression/value.cpp
+++ b/src/mbgl/style/expression/value.cpp
@@ -108,13 +108,9 @@ Value ValueConverter<float>::toExpressionValue(const float value) {
}
optional<float> ValueConverter<float>::fromExpressionValue(const Value& value) {
- if (value.template is<double>()) {
- double v = value.template get<double>();
- if (v <= std::numeric_limits<float>::max()) {
- return static_cast<float>(v);
- }
- }
- return optional<float>();
+ return value.template is<double>()
+ ? static_cast<float>(value.template get<double>())
+ : optional<float>();
}