From b9c7e1bdd99b4c6d37672ef34ffe178d4bc54ad3 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 5 Aug 2014 18:04:31 -0700 Subject: 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. --- include/mbgl/util/interpolate.hpp | 25 +++++++++++++++++++++++++ include/mbgl/util/math.hpp | 5 ----- include/mbgl/util/transition.hpp | 6 ------ 3 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 include/mbgl/util/interpolate.hpp (limited to 'include/mbgl/util') diff --git a/include/mbgl/util/interpolate.hpp b/include/mbgl/util/interpolate.hpp new file mode 100644 index 0000000000..e8c3389350 --- /dev/null +++ b/include/mbgl/util/interpolate.hpp @@ -0,0 +1,25 @@ +#ifndef MBGL_UTIL_INTERPOLATE +#define MBGL_UTIL_INTERPOLATE + +namespace mbgl { +namespace util { + +template +T interpolate(const T a, const T b, const double t) { + return a * (1.0 - t) + b * t; +} + +template +inline std::array interpolate(const std::array& a, const std::array& 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 diff --git a/include/mbgl/util/math.hpp b/include/mbgl/util/math.hpp index 277fdc8fc3..fde2a4720b 100644 --- a/include/mbgl/util/math.hpp +++ b/include/mbgl/util/math.hpp @@ -57,11 +57,6 @@ inline T angle_to(const vec2& a, const vec2& b) { return std::atan2(a.y - b.y, a.x - b.x); } -template -inline T interp(S1 a, S2 b, T t) { - return (a * ((T)1 - t)) + (b * t); -} - // Reflect an angle around 0 degrees template inline std::array flip(const std::array& c) { diff --git a/include/mbgl/util/transition.hpp b/include/mbgl/util/transition.hpp index b12527124e..8a6836c885 100644 --- a/include/mbgl/util/transition.hpp +++ b/include/mbgl/util/transition.hpp @@ -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 interpolateFloatArray(std::array from, std::array to, double t) const; - protected: const timestamp start, duration; }; -- cgit v1.2.1