diff --git a/src/style-spec/function/index.js b/src/style-spec/function/index.js index e3c5db5ea9c..0f304ebd5ef 100644 --- a/src/style-spec/function/index.js +++ b/src/style-spec/function/index.js @@ -292,7 +292,9 @@ function interpolationFactor(input, base, lowerValue, upperValue) { const difference = upperValue - lowerValue; const progress = input - lowerValue; - if (base === 1) { + if (difference === 0) { + return 0; + } else if (base === 1) { return progress / difference; } else { return (Math.pow(base, progress) - 1) / (Math.pow(base, difference) - 1); diff --git a/test/unit/style-spec/function.test.js b/test/unit/style-spec/function.test.js index 0248082e23c..16ad4a64b1c 100644 --- a/test/unit/style-spec/function.test.js +++ b/test/unit/style-spec/function.test.js @@ -56,9 +56,9 @@ test('binary search', (t) => { type: 'number', function: 'interpolated' }); - // Nan because the interpolation will fail when given to stops with the same value. - // This is however more desirable than looping forever. - t.equal(isNaN(f(17)), true); + + t.equal(f(17), 11); + t.end(); }); t.end();