[core] Handle NaN input to interpolate and step

This commit is contained in:
John Firebaugh
2018-01-10 11:48:06 -08:00
parent ecbb0baf60
commit cedda5ef4f
4 changed files with 20 additions and 12 deletions

View File

@@ -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." };
}

View File

@@ -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",

View File

@@ -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." };

View File

@@ -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>();
}