Consolidate duplicate interpolation definitions
While here, do not interpolate style properties that are not transitionable. The previous behavior was to switch from old to new value halfway through the transition; now the new value is used immediately, as in JS.
This commit is contained in:
@@ -51,6 +51,7 @@ private:
|
||||
// aplied classes in order.
|
||||
template <typename T> void applyStyleProperties(float z, timestamp now);
|
||||
template <typename T> void applyStyleProperty(PropertyKey key, T &, float z, timestamp now);
|
||||
template <typename T> void applyTransitionedStyleProperty(PropertyKey key, T &, float z, timestamp now);
|
||||
|
||||
// Removes all expired style transitions.
|
||||
void cleanupAppliedStyleProperties(timestamp now);
|
||||
|
||||
25
include/mbgl/util/interpolate.hpp
Normal file
25
include/mbgl/util/interpolate.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef MBGL_UTIL_INTERPOLATE
|
||||
#define MBGL_UTIL_INTERPOLATE
|
||||
|
||||
namespace mbgl {
|
||||
namespace util {
|
||||
|
||||
template <typename T>
|
||||
T interpolate(const T a, const T b, const double t) {
|
||||
return a * (1.0 - t) + b * t;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline std::array<T, 4> interpolate(const std::array<T, 4>& a, const std::array<T, 4>& b, const double t) {
|
||||
return {{
|
||||
interpolate(a[0], b[0], t),
|
||||
interpolate(a[1], b[1], t),
|
||||
interpolate(a[2], b[2], t),
|
||||
interpolate(a[3], b[3], t)
|
||||
}};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -57,11 +57,6 @@ inline T angle_to(const vec2<S>& a, const vec2<S>& b) {
|
||||
return std::atan2(a.y - b.y, a.x - b.x);
|
||||
}
|
||||
|
||||
template <typename T, typename S1, typename S2>
|
||||
inline T interp(S1 a, S2 b, T t) {
|
||||
return (a * ((T)1 - t)) + (b * t);
|
||||
}
|
||||
|
||||
// Reflect an angle around 0 degrees
|
||||
template <typename T>
|
||||
inline std::array<T, 2> flip(const std::array<T, 2>& c) {
|
||||
|
||||
@@ -29,12 +29,6 @@ public:
|
||||
virtual state update(timestamp now) const = 0;
|
||||
virtual ~transition();
|
||||
|
||||
protected:
|
||||
double interpolateDouble(double from, double to, double t) const;
|
||||
float interpolateFloat(float from, float to, double t) const;
|
||||
Color interpolateColor(Color from, Color to, double t) const;
|
||||
std::array<float, 2> interpolateFloatArray(std::array<float, 2> from, std::array<float, 2> to, double t) const;
|
||||
|
||||
protected:
|
||||
const timestamp start, duration;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user