diff options
author | Gali Nelle <galinelle.mapbox@gmail.com> | 2020-04-06 10:12:56 +0300 |
---|---|---|
committer | galinelle <paolo.angelelli@mapbox.com> | 2020-04-08 14:00:26 +0300 |
commit | 8e581c88ea855998a2746e57f1a5fc46ee62faee (patch) | |
tree | 9a158b1a4281a6c894025cc6758a0c9c59dfd5b0 /include/mbgl/util | |
parent | 9a55c282fecfdd76b1acdf64cef0ce2ed99472ef (diff) | |
download | qtlocation-mapboxgl-8e581c88ea855998a2746e57f1a5fc46ee62faee.tar.gz |
Make location indicator bearing a paint property
This change introduces a new property type, Rotation, that uses
a custom interpolator, and that is currently applied to
all style properties named "bearing", with a period attribute.
Diffstat (limited to 'include/mbgl/util')
-rw-r--r-- | include/mbgl/util/interpolate.hpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/include/mbgl/util/interpolate.hpp b/include/mbgl/util/interpolate.hpp index aff730a0a2..566f2b0a6b 100644 --- a/include/mbgl/util/interpolate.hpp +++ b/include/mbgl/util/interpolate.hpp @@ -1,9 +1,10 @@ #pragma once +#include <mbgl/style/expression/value.hpp> +#include <mbgl/style/position.hpp> +#include <mbgl/style/rotation.hpp> #include <mbgl/util/color.hpp> #include <mbgl/util/range.hpp> -#include <mbgl/style/position.hpp> -#include <mbgl/style/expression/value.hpp> #include <array> #include <vector> @@ -102,6 +103,27 @@ public: } }; +template <> +struct Interpolator<style::Rotation> { +public: + style::Rotation operator()(const style::Rotation& a, const style::Rotation& b, const double t) { + assert(a.period() == b.period()); + auto period = a.period(); + auto aAngle = std::fmod(a.getAngle(), period); + auto bAngle = std::fmod(b.getAngle(), period); + + if (aAngle - bAngle > period * 0.5) { + return {std::fmod(aAngle * (1.0 - t) + (bAngle + period) * t, period)}; + } + + if (aAngle - bAngle < period * -0.5) { + return {std::fmod((aAngle + period) * (1.0 - t) + bAngle * t, period)}; + } + + return {aAngle * (1.0 - t) + bAngle * t}; + } +}; + struct Uninterpolated { template <class T> T operator()(const T& a, const T&, const double) const { |