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

Commit

Permalink
[core] More complete fix for composite function interpolation edge case
Browse files Browse the repository at this point in the history
b5b4549 / #8613 handled the edge case for layout properties, but not paint properties. Move the check for a degenerate range to interpolationFactor in order to handle both correctly.
  • Loading branch information
jfirebaugh committed Apr 20, 2017
1 parent c6be40b commit 3c23faf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
3 changes: 0 additions & 3 deletions include/mbgl/style/function/composite_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ class CompositeFunction {
T evaluate(float zoom, const GeometryTileFeature& feature, T finalDefaultValue) const {
std::tuple<Range<float>, Range<InnerStops>> ranges = coveringRanges(zoom);
Range<T> 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,
Expand Down
4 changes: 3 additions & 1 deletion src/mbgl/util/interpolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ namespace util {
float interpolationFactor(float base, Range<float> range, float z) {
const float zoomDiff = range.max - range.min;
const float zoomProgress = z - range.min;
if (base == 1.0f) {
if (zoomDiff == 0) {
return 0;
} else if (base == 1.0f) {
return zoomProgress / zoomDiff;
} else {
return (std::pow(base, zoomProgress) - 1) / (std::pow(base, zoomDiff) - 1);
Expand Down

0 comments on commit 3c23faf

Please sign in to comment.