Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Handle NaN input to interpolate and step
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh committed Jan 10, 2018
1 parent ecbb0ba commit cedda5e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
12 changes: 9 additions & 3 deletions include/mbgl/style/expression/interpolate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <memory>
#include <map>

#include <cmath>

namespace mbgl {
namespace style {
Expand Down Expand Up @@ -109,9 +109,15 @@ class Interpolate : public InterpolateBase {

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." };
}
Expand Down
1 change: 0 additions & 1 deletion platform/node/test/ignores.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion src/mbgl/style/expression/step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
#include <mbgl/style/expression/get_covering_stops.hpp>
#include <mbgl/util/string.hpp>

#include <cmath>

namespace mbgl {
namespace style {
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." };
Expand Down
10 changes: 3 additions & 7 deletions src/mbgl/style/expression/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
}


Expand Down

0 comments on commit cedda5e

Please sign in to comment.