diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-04-06 16:17:39 +0300 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-04-06 16:17:39 +0300 |
commit | d1aff1c73f542f1ae17b76555b6343da4f1ae474 (patch) | |
tree | d773f299f8bab94a9ac454fd6288d4cc1a1decfb | |
parent | 3911ef6a0f4a47343429482e0e37a90e5b2fd606 (diff) | |
download | qtlocation-mapboxgl-upstream/galinelle_locationComponent_interpolate_rotation.tar.gz |
Add rotation.cpp / hpp filesupstream/galinelle_locationComponent_interpolate_rotation
-rw-r--r-- | include/mbgl/style/conversion/rotation.hpp | 18 | ||||
-rw-r--r-- | include/mbgl/style/rotation.hpp | 29 | ||||
-rw-r--r-- | src/mbgl/style/conversion/rotation.cpp | 20 |
3 files changed, 67 insertions, 0 deletions
diff --git a/include/mbgl/style/conversion/rotation.hpp b/include/mbgl/style/conversion/rotation.hpp new file mode 100644 index 0000000000..b250b6e947 --- /dev/null +++ b/include/mbgl/style/conversion/rotation.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include <mbgl/style/rotation.hpp> +#include <mbgl/style/conversion.hpp> +#include <mbgl/util/optional.hpp> + +namespace mbgl { +namespace style { +namespace conversion { + +template <> +struct Converter<style::Rotation> { + optional<style::Rotation> operator()(const Convertible& value, Error& error) const; +}; + +} // namespace conversion +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/rotation.hpp b/include/mbgl/style/rotation.hpp new file mode 100644 index 0000000000..30adfb8d50 --- /dev/null +++ b/include/mbgl/style/rotation.hpp @@ -0,0 +1,29 @@ +#pragma once + +namespace mbgl { +namespace style { + +// Could be made a template class if needed +// template <size_t Period> +// 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/src/mbgl/style/conversion/rotation.cpp b/src/mbgl/style/conversion/rotation.cpp new file mode 100644 index 0000000000..9b382b7400 --- /dev/null +++ b/src/mbgl/style/conversion/rotation.cpp @@ -0,0 +1,20 @@ +#include <mbgl/style/conversion/rotation.hpp> +#include <mbgl/style/conversion/constant.hpp> +#include <mbgl/style/conversion_impl.hpp> + +namespace mbgl { +namespace style { +namespace conversion { + +optional<style::Rotation> Converter<style::Rotation>::operator()(const Convertible& value, Error& error) const { + optional<double> converted = toDouble(value); + if (!converted) { + error.message = "value must be a number"; + return nullopt; + } + return {*converted}; +} + +} // namespace conversion +} // namespace style +} // namespace mbgl |