[core] Handle NaN input to interpolate and step
This commit is contained in:
@@ -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." };
|
||||
|
||||
@@ -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>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user