From cedda5ef4f73fccfc795e6bc48b368e48f11ad8d Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 10 Jan 2018 11:48:06 -0800 Subject: [core] Handle NaN input to interpolate and step --- src/mbgl/style/expression/step.cpp | 9 ++++++++- src/mbgl/style/expression/value.cpp | 10 +++------- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'src') 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 #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 b75f471ce3..ef4769df02 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(); } -- cgit v1.2.1