Files
MapLibreParticleLab/src/mbgl/util/interpolate.cpp
John Firebaugh 3c23faf65a [core] More complete fix for composite function interpolation edge case
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.
2017-04-20 16:11:57 -07:00

22 lines
516 B
C++

#include <mbgl/util/interpolate.hpp>
#include <cmath>
namespace mbgl {
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 (zoomDiff == 0) {
return 0;
} else if (base == 1.0f) {
return zoomProgress / zoomDiff;
} else {
return (std::pow(base, zoomProgress) - 1) / (std::pow(base, zoomDiff) - 1);
}
}
} // namespace util
} // namespace mbgl