diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2014-12-16 10:35:19 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:34:58 +0300 |
commit | 28c8f64c689ccf34f67f41bccda2878bce374b96 (patch) | |
tree | 90dee19d70a8e45438a3e6e14c4a2dc250086044 /geometry | |
parent | 7d37e2c812a5fe288cdb91f69711beb5ed4a8c35 (diff) |
Taking into account all outgoing edges for a turn generation.
Diffstat (limited to 'geometry')
-rw-r--r-- | geometry/angles.hpp | 11 | ||||
-rw-r--r-- | geometry/geometry_tests/angle_test.cpp | 7 |
2 files changed, 18 insertions, 0 deletions
diff --git a/geometry/angles.hpp b/geometry/angles.hpp index 9249fa9813..0d218ea6d7 100644 --- a/geometry/angles.hpp +++ b/geometry/angles.hpp @@ -76,6 +76,17 @@ namespace ang return atan2(p2.y - p1.y, p2.x - p1.x); } + /// Returns an angle from vector [p, p1] to vector [p, p2]. A counterclockwise rotation. + /// Angle is in range [0, 2 * pi] + template <typename T> + inline T TwoVectorsAngle(m2::Point<T> const & p, m2::Point<T> const & p1, m2::Point<T> const & p2) + { + T a = ang::AngleTo(p, p2) - ang::AngleTo(p, p1); + while (a < 0) + a += math::twicePi; + return a; + } + double AngleIn2PI(double ang); /// @return Oriented angle (<= PI) from rad1 to rad2. diff --git a/geometry/geometry_tests/angle_test.cpp b/geometry/geometry_tests/angle_test.cpp index b77f30e351..4e5e0f912c 100644 --- a/geometry/geometry_tests/angle_test.cpp +++ b/geometry/geometry_tests/angle_test.cpp @@ -73,3 +73,10 @@ UNIT_TEST(ShortestDistance) TEST_ALMOST_EQUAL(ang::GetShortestDistance(math::pi - 1, 0), -math::pi + 1, ()); TEST_ALMOST_EQUAL(ang::GetShortestDistance(math::pi + 1, 0), math::pi - 1, ()); } + +UNIT_TEST(TwoVectorsAngle){ + TEST_ALMOST_EQUAL(ang::TwoVectorsAngle(m2::Point<double>({0, 0}), + m2::Point<double>({0, 1}), m2::Point<double>(1, 0)), 3 * math::pi2, ()); + TEST_ALMOST_EQUAL(ang::TwoVectorsAngle(m2::Point<double>({1, 1}), + m2::Point<double>({2, 2}), m2::Point<double>(1, 2)), math::pi4, ()); +} |