From cedda5ef4f73fccfc795e6bc48b368e48f11ad8d Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 10 Jan 2018 11:48:06 -0800 Subject: [PATCH] [core] Handle NaN input to interpolate and step --- include/mbgl/style/expression/interpolate.hpp | 12 +++++++++--- platform/node/test/ignores.json | 1 - src/mbgl/style/expression/step.cpp | 9 ++++++++- src/mbgl/style/expression/value.cpp | 10 +++------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/include/mbgl/style/expression/interpolate.hpp b/include/mbgl/style/expression/interpolate.hpp index 439122f91..fd9ec25a2 100644 --- a/include/mbgl/style/expression/interpolate.hpp +++ b/include/mbgl/style/expression/interpolate.hpp @@ -11,7 +11,7 @@ #include #include - +#include 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(*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 7cb3560f4..3f904c304 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 bfcb6fd27..11bf543b7 100644 --- a/src/mbgl/style/expression/step.cpp +++ b/src/mbgl/style/expression/step.cpp @@ -2,6 +2,7 @@ #include #include +#include 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(*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 b75f471ce..ef4769df0 100644 --- a/src/mbgl/style/expression/value.cpp +++ b/src/mbgl/style/expression/value.cpp @@ -108,13 +108,9 @@ Value ValueConverter::toExpressionValue(const float value) { } optional ValueConverter::fromExpressionValue(const Value& value) { - if (value.template is()) { - double v = value.template get(); - if (v <= std::numeric_limits::max()) { - return static_cast(v); - } - } - return optional(); + return value.template is() + ? static_cast(value.template get()) + : optional(); }