diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2017-07-19 17:47:02 +0300 |
---|---|---|
committer | Vladimir Byko-Ianko <bykoianko@gmail.com> | 2017-07-25 09:08:01 +0300 |
commit | 689114b8db33771b3b512b820ae1ecafbc190c49 (patch) | |
tree | 171f5b81733aa59ad9d7fb58f4f96a8b16d6cf5a | |
parent | b8e75c54e87e5d2e965526b17151a21a8604f646 (diff) |
Recovering FollowedPolyline::Append() and FollowedPolyline::Pop() and adding tests.
-rw-r--r-- | geometry/polyline2d.hpp | 10 | ||||
-rw-r--r-- | routing/base/followed_polyline.hpp | 13 | ||||
-rw-r--r-- | routing/routing_tests/followed_polyline_test.cpp | 25 |
3 files changed, 48 insertions, 0 deletions
diff --git a/geometry/polyline2d.hpp b/geometry/polyline2d.hpp index ff0170b4bd..9e96516bd5 100644 --- a/geometry/polyline2d.hpp +++ b/geometry/polyline2d.hpp @@ -70,6 +70,16 @@ public: void Clear() { m_points.clear(); } void Add(Point<T> const & pt) { m_points.push_back(pt); } + void Append(Polyline const & poly) + { + m_points.insert(m_points.end(), poly.m_points.cbegin(), poly.m_points.cend()); + } + + void PopBack() + { + ASSERT(!m_points.empty(), ()); + m_points.pop_back(); + } void Swap(Polyline & rhs) { m_points.swap(rhs.m_points); } size_t GetSize() const { return m_points.size(); } diff --git a/routing/base/followed_polyline.hpp b/routing/base/followed_polyline.hpp index 1cbaca4de6..4446590aa9 100644 --- a/routing/base/followed_polyline.hpp +++ b/routing/base/followed_polyline.hpp @@ -21,6 +21,19 @@ public: } void Swap(FollowedPolyline & rhs); + + void Append(FollowedPolyline const & poly) + { + m_poly.Append(poly.m_poly); + Update(); + } + + void PopBack() + { + m_poly.PopBack(); + Update(); + } + bool IsValid() const { return (m_current.IsValid() && m_poly.GetSize() > 1); } m2::PolylineD const & GetPolyline() const { return m_poly; } std::vector<double> const & GetSegDistanceM() const { return m_segDistance; } diff --git a/routing/routing_tests/followed_polyline_test.cpp b/routing/routing_tests/followed_polyline_test.cpp index 2bf7f45c1b..6f200b08c7 100644 --- a/routing/routing_tests/followed_polyline_test.cpp +++ b/routing/routing_tests/followed_polyline_test.cpp @@ -11,8 +11,33 @@ using namespace routing; namespace { static const m2::PolylineD kTestDirectedPolyline({{0.0, 0.0}, {3.0, 0.0}, {5.0, 0.0}}); + static const m2::PolylineD kTestDirectedPolyline2({{6.0, 0.0}, {7.0, 0.0}}); } // namespace +UNIT_TEST(FollowedPolylineAppend) +{ + FollowedPolyline followedPolyline1(kTestDirectedPolyline.Begin(), kTestDirectedPolyline.End()); + FollowedPolyline const followedPolyline2(kTestDirectedPolyline2.Begin(), kTestDirectedPolyline2.End()); + + TEST_EQUAL(followedPolyline1.GetPolyline(), kTestDirectedPolyline, ()); + followedPolyline1.Append(followedPolyline2); + TEST_EQUAL(followedPolyline1.GetPolyline().GetSize(), 5, ()); + + m2::PolylineD polyline1 = kTestDirectedPolyline; + polyline1.Append(kTestDirectedPolyline2); + TEST_EQUAL(followedPolyline1.GetPolyline(), polyline1, ()); +} + +UNIT_TEST(FollowedPolylinePop) +{ + FollowedPolyline followedPolyline(kTestDirectedPolyline.Begin(), kTestDirectedPolyline.End()); + + TEST_EQUAL(followedPolyline.GetPolyline(), kTestDirectedPolyline, ()); + TEST_EQUAL(followedPolyline.GetPolyline().GetSize(), 3, ()); + followedPolyline.PopBack(); + TEST_EQUAL(followedPolyline.GetPolyline().GetSize(), 2, ()); +} + UNIT_TEST(FollowedPolylineInitializationFogTest) { FollowedPolyline polyline(kTestDirectedPolyline.Begin(), kTestDirectedPolyline.End()); |