From 8e581c88ea855998a2746e57f1a5fc46ee62faee Mon Sep 17 00:00:00 2001 From: Gali Nelle Date: Mon, 6 Apr 2020 10:12:56 +0300 Subject: 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. --- include/mbgl/style/conversion/rotation.hpp | 18 +++++++++++++++ include/mbgl/style/conversion_impl.hpp | 6 +++++ include/mbgl/style/expression/value.hpp | 8 +++++++ include/mbgl/style/layers/background_layer.hpp | 1 - include/mbgl/style/layers/circle_layer.hpp | 1 - include/mbgl/style/layers/fill_extrusion_layer.hpp | 1 - include/mbgl/style/layers/fill_layer.hpp | 1 - include/mbgl/style/layers/heatmap_layer.hpp | 1 - include/mbgl/style/layers/hillshade_layer.hpp | 1 - include/mbgl/style/layers/layer.hpp.ejs | 5 +++++ include/mbgl/style/layers/line_layer.hpp | 1 - .../mbgl/style/layers/location_indicator_layer.hpp | 12 +++++----- include/mbgl/style/layers/raster_layer.hpp | 1 - include/mbgl/style/rotation.hpp | 25 +++++++++++++++++++++ include/mbgl/util/interpolate.hpp | 26 ++++++++++++++++++++-- 15 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 include/mbgl/style/conversion/rotation.hpp create mode 100644 include/mbgl/style/rotation.hpp (limited to 'include') diff --git a/include/mbgl/style/conversion/rotation.hpp b/include/mbgl/style/conversion/rotation.hpp new file mode 100644 index 0000000000..86d67240fd --- /dev/null +++ b/include/mbgl/style/conversion/rotation.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +struct Converter { + optional operator()(const Convertible& value, Error& error) const; +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp index 79e9301842..8652a355f1 100644 --- a/include/mbgl/style/conversion_impl.hpp +++ b/include/mbgl/style/conversion_impl.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -343,6 +344,11 @@ struct ValueFactory { } }; +template <> +struct ValueFactory { + static Value make(const Rotation& rotation) { return {rotation.getAngle()}; } +}; + template Value makeValue(T&& arg) { return ValueFactory>::make(std::forward(arg)); diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp index 902f5ae209..6f12bb9336 100644 --- a/include/mbgl/style/expression/value.hpp +++ b/include/mbgl/style/expression/value.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -147,6 +148,13 @@ std::vector> fromExpressionValues(const std::vector> return result; } +template <> +struct ValueConverter { + static type::Type expressionType() { return type::Number; } + static Value toExpressionValue(const mbgl::style::Rotation& value); + static optional fromExpressionValue(const Value& v); +}; + } // namespace expression } // namespace style } // namespace mbgl diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index 9fdfd3ac92..2a46b2fc21 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index dd5b674002..f0e9787caa 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp index ca33c6c3f8..3e4973b82c 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index 4a1f09cca0..fb386c4b11 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp index 588aaa81df..371e9a8aa4 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp index c501e80b8d..7149fb46dd 100644 --- a/include/mbgl/style/layers/hillshade_layer.hpp +++ b/include/mbgl/style/layers/hillshade_layer.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index a083829f60..a81aaa9e16 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -15,7 +15,12 @@ #include #include #include +<% if (type === 'location-indicator') { -%> +#include +<% } -%> +<% if (type === 'symbol') { -%> #include +<% } -%> #include <% if (type === 'line' || type === 'symbol') { -%> diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index 2186f16669..7d7da47bf9 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include diff --git a/include/mbgl/style/layers/location_indicator_layer.hpp b/include/mbgl/style/layers/location_indicator_layer.hpp index e9e67c1a20..f112664dab 100644 --- a/include/mbgl/style/layers/location_indicator_layer.hpp +++ b/include/mbgl/style/layers/location_indicator_layer.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include namespace mbgl { @@ -22,10 +22,6 @@ public: // Layout properties - static PropertyValue getDefaultBearing(); - const PropertyValue& getBearing() const; - void setBearing(const PropertyValue&); - static PropertyValue getDefaultBearingImage(); const PropertyValue& getBearingImage() const; void setBearingImage(const PropertyValue&); @@ -66,6 +62,12 @@ public: void setAccuracyRadiusColorTransition(const TransitionOptions&); TransitionOptions getAccuracyRadiusColorTransition() const; + static PropertyValue getDefaultBearing(); + const PropertyValue& getBearing() const; + void setBearing(const PropertyValue&); + void setBearingTransition(const TransitionOptions&); + TransitionOptions getBearingTransition() const; + static PropertyValue getDefaultBearingImageSize(); const PropertyValue& getBearingImageSize() const; void setBearingImageSize(const PropertyValue&); diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index df82c93660..78fa3db23b 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include namespace mbgl { diff --git a/include/mbgl/style/rotation.hpp b/include/mbgl/style/rotation.hpp new file mode 100644 index 0000000000..862ede93b7 --- /dev/null +++ b/include/mbgl/style/rotation.hpp @@ -0,0 +1,25 @@ +#pragma once + +namespace mbgl { +namespace style { + +// Could be made a template class if needed +// template +// size_t period() const noexcept { return Period; } +class Rotation { +public: + Rotation() = default; + Rotation(double angle_) : angle(angle_) {} + double period() const noexcept { return 360.0; } + double getAngle() const noexcept { return angle; } + + friend bool operator==(const Rotation& lhs, const Rotation& rhs) { return lhs.angle == rhs.angle; } + + friend bool operator!=(const Rotation& lhs, const Rotation& rhs) { return !(lhs == rhs); } + +private: + double angle; +}; + +} // namespace style +} // namespace mbgl 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 +#include +#include #include #include -#include -#include #include #include @@ -102,6 +103,27 @@ public: } }; +template <> +struct Interpolator { +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 T operator()(const T& a, const T&, const double) const { -- cgit v1.2.1