summaryrefslogtreecommitdiff
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
parentecbb0baf60138cea2c72ec4e75b788ca59d86e14 (diff)
downloadqtlocation-mapboxgl-cedda5ef4f73fccfc795e6bc48b368e48f11ad8d.tar.gz
[core] Handle NaN input to interpolate and step
-rw-r--r--include/mbgl/style/expression/interpolate.hpp12
-rw-r--r--platform/node/test/ignores.json1
-rw-r--r--src/mbgl/style/expression/step.cpp9
-rw-r--r--src/mbgl/style/expression/value.cpp10
4 files changed, 20 insertions, 12 deletions
diff --git a/include/mbgl/style/expression/interpolate.hpp b/include/mbgl/style/expression/interpolate.hpp
index 439122f91c..fd9ec25a2c 100644
--- a/include/mbgl/style/expression/interpolate.hpp
+++ b/include/mbgl/style/expression/interpolate.hpp
@@ -11,7 +11,7 @@
#include <memory>
#include <map>
-
+#include <cmath>
namespace mbgl {
namespace style {
@@ -109,9 +109,15 @@ public:
EvaluationResult evaluate(const EvaluationContext& params) const override {
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 exponential curve." };
}
diff --git a/platform/node/test/ignores.json b/platform/node/test/ignores.json
index 7cb3560f4d..3f904c3048 100644
--- a/platform/node/test/ignores.json
+++ b/platform/node/test/ignores.json
@@ -50,7 +50,6 @@
"render-tests/regressions/mapbox-gl-js#2762": "https://github.com/mapbox/mapbox-gl-native/issues/10619",
"render-tests/regressions/mapbox-gl-js#2769": "https://github.com/mapbox/mapbox-gl-native/issues/10619",
"render-tests/regressions/mapbox-gl-js#3682": "https://github.com/mapbox/mapbox-gl-js/issues/3682",
- "render-tests/regressions/mapbox-gl-js#4172": "https://github.com/mapbox/mapbox-gl-native/issues/10618",
"render-tests/regressions/mapbox-gl-js#5370": "skip - https://github.com/mapbox/mapbox-gl-native/pull/9439",
"render-tests/regressions/mapbox-gl-js#5599": "https://github.com/mapbox/mapbox-gl-native/issues/10399",
"render-tests/regressions/mapbox-gl-js#5740": "https://github.com/mapbox/mapbox-gl-native/issues/10619",
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>();
}