From b5b4549b6d80e4a1f45e766161bafd52a064c91d Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Mon, 3 Apr 2017 12:25:36 -0400 Subject: Fix edge case in composite function interpolation (#8613) This fixes a bug where, for a zoom value greater than that of the highest zoom stop, composite function interpolation would return nan. (Blocking a render test over in #8593) * Add failing tests for composite function edge case The failing cases here are: - Should interpolate before the first stop - Should interpolate past the last stop * Fix edge case in composite function interpolation * Hold functions constant outside stop-defined domain --- include/mbgl/style/function/composite_function.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include/mbgl/style') diff --git a/include/mbgl/style/function/composite_function.hpp b/include/mbgl/style/function/composite_function.hpp index b31329b75e..2b4ae504ca 100644 --- a/include/mbgl/style/function/composite_function.hpp +++ b/include/mbgl/style/function/composite_function.hpp @@ -56,9 +56,13 @@ public: assert(!s.stops.empty()); auto minIt = s.stops.lower_bound(zoom); auto maxIt = s.stops.upper_bound(zoom); - if (minIt != s.stops.begin()) { + + // lower_bound yields first element >= zoom, but we want the *last* + // element <= zoom, so if we found a stop > zoom, back up by one. + if (minIt != s.stops.begin() && minIt->first > zoom) { minIt--; } + return std::make_tuple( Range { minIt == s.stops.end() ? s.stops.rbegin()->first : minIt->first, @@ -96,6 +100,9 @@ public: T evaluate(float zoom, const GeometryTileFeature& feature, T finalDefaultValue) const { std::tuple, Range> ranges = coveringRanges(zoom); Range resultRange = evaluate(std::get<1>(ranges), feature, finalDefaultValue); + // If the covering stop range is constant, just return the output value directly. + if (resultRange.min == resultRange.max) return resultRange.min; + // Otherwise, interpolate between the two stops. return util::interpolate( resultRange.min, resultRange.max, -- cgit v1.2.1