From cd91664935303c2490d6ce9dbfe7d6c719404a95 Mon Sep 17 00:00:00 2001 From: Gali Nelle Date: Tue, 7 Apr 2020 15:06:55 +0300 Subject: [PATCH] Add unit tests for Rotation interpolator --- include/mbgl/style/rotation.hpp | 6 +++--- test/CMakeLists.txt | 1 + test/util/rotation.test.cpp | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 test/util/rotation.test.cpp diff --git a/include/mbgl/style/rotation.hpp b/include/mbgl/style/rotation.hpp index 862ede93b..96b047c68 100644 --- a/include/mbgl/style/rotation.hpp +++ b/include/mbgl/style/rotation.hpp @@ -1,5 +1,5 @@ #pragma once - +#include namespace mbgl { namespace style { @@ -9,8 +9,8 @@ namespace style { class Rotation { public: Rotation() = default; - Rotation(double angle_) : angle(angle_) {} - double period() const noexcept { return 360.0; } + Rotation(double angle_) : angle(mbgl::util::wrap(angle_, 0, period())) {} + constexpr 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; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 35d8f2300..3aa02a1c7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -94,6 +94,7 @@ add_library( ${PROJECT_SOURCE_DIR}/test/util/pass.test.cpp ${PROJECT_SOURCE_DIR}/test/util/position.test.cpp ${PROJECT_SOURCE_DIR}/test/util/projection.test.cpp + ${PROJECT_SOURCE_DIR}/test/util/rotation.test.cpp ${PROJECT_SOURCE_DIR}/test/util/run_loop.test.cpp ${PROJECT_SOURCE_DIR}/test/util/string.test.cpp ${PROJECT_SOURCE_DIR}/test/util/text_conversions.test.cpp diff --git a/test/util/rotation.test.cpp b/test/util/rotation.test.cpp new file mode 100644 index 000000000..57189ae98 --- /dev/null +++ b/test/util/rotation.test.cpp @@ -0,0 +1,23 @@ +#include + +#include +#include +#include +#include + +using namespace mbgl; +using namespace style; + +Rotation createRotation(double angle) { + return Rotation(angle); +} + +TEST(Rotation, Calculations) { + Rotation rot(42); + EXPECT_EQ(rot, Rotation(42 + 360)); + Rotation rot2(-42); + EXPECT_EQ(rot2, Rotation(360 - 42)); + + mbgl::util::Interpolator i; + EXPECT_NEAR(i(rot, rot2, 0.5).getAngle(), 0.0, 0.00001); +}