Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLev Dragunov <l.dragunov@corp.mail.ru>2015-08-18 18:46:42 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 03:01:51 +0300
commitec7362ca609a48e99d02e24a4b4f2f4bdc39c221 (patch)
tree0756f0d580e12d41270a2d0fa227076832f8b6c1 /routing
parent33fb379f22c4fd7f243cc74e2d3dd4c7b50b321e (diff)
Another PR fixes.
Diffstat (limited to 'routing')
-rw-r--r--routing/base/followed_polyline.cpp2
-rw-r--r--routing/base/followed_polyline.hpp4
-rw-r--r--routing/route.cpp6
-rw-r--r--routing/routing_tests/followed_polyline_test.cpp24
4 files changed, 28 insertions, 8 deletions
diff --git a/routing/base/followed_polyline.cpp b/routing/base/followed_polyline.cpp
index 55e899baf3..05491a038e 100644
--- a/routing/base/followed_polyline.cpp
+++ b/routing/base/followed_polyline.cpp
@@ -52,7 +52,7 @@ double FollowedPolyline::GetDistanceFromBeginM() const
ASSERT(IsValid(), ());
ASSERT(m_current.IsValid(), ());
- return m_current.m_ind > 0 ? m_segDistance[m_current.m_ind] : 0.0 +
+ return (m_current.m_ind > 0 ? m_segDistance[m_current.m_ind - 1] : 0.0) +
MercatorBounds::DistanceOnEarth(m_current.m_pt, m_poly.GetPoint(m_current.m_ind));
}
diff --git a/routing/base/followed_polyline.hpp b/routing/base/followed_polyline.hpp
index 02a9d4342f..a7224a170f 100644
--- a/routing/base/followed_polyline.hpp
+++ b/routing/base/followed_polyline.hpp
@@ -20,7 +20,7 @@ public:
void Swap(FollowedPolyline & rhs);
- bool IsValid() const { return (m_current.IsValid() && m_poly.GetSize() > 0); }
+ bool IsValid() const { return (m_current.IsValid() && m_poly.GetSize() > 1); }
m2::PolylineD const & GetPolyline() const { return m_poly; }
@@ -65,7 +65,7 @@ private:
m2::PolylineD m_poly;
- /// Iterator with the current position. Position sets with UpdatePtojection methods.
+ /// Iterator with the current position. Position sets with UpdateProjection methods.
mutable Iter m_current;
/// Precalculated info for fast projection finding.
vector<m2::ProjectionToSection<m2::PointD>> m_segProj;
diff --git a/routing/route.cpp b/routing/route.cpp
index 064310a0a9..4ae404d2eb 100644
--- a/routing/route.cpp
+++ b/routing/route.cpp
@@ -62,6 +62,10 @@ void Route::GetTurnsDistances(vector<double> & distances) const
auto const & polyline = m_poly.GetPolyline();
for (auto currentTurn = m_turns.begin(); currentTurn != m_turns.end(); ++currentTurn)
{
+ // Skip turns at side points of the polyline geometry. We can't display them properly.
+ if (currentTurn->m_index == 0 || currentTurn->m_index == (polyline.GetSize() - 1))
+ continue;
+
uint32_t formerTurnIndex = 0;
if (currentTurn != m_turns.begin())
formerTurnIndex = (currentTurn - 1)->m_index;
@@ -71,8 +75,6 @@ void Route::GetTurnsDistances(vector<double> & distances) const
turns::CalculateMercatorDistanceAlongPath(formerTurnIndex, currentTurn->m_index, polyline.GetPoints());
mercatorDistance += mercatorDistanceBetweenTurns;
- if (currentTurn->m_index == 0 || currentTurn->m_index == (polyline.GetSize() - 1))
- continue;
distances.push_back(mercatorDistance);
}
}
diff --git a/routing/routing_tests/followed_polyline_test.cpp b/routing/routing_tests/followed_polyline_test.cpp
index af0aabb741..2bf7f45c1b 100644
--- a/routing/routing_tests/followed_polyline_test.cpp
+++ b/routing/routing_tests/followed_polyline_test.cpp
@@ -67,21 +67,27 @@ UNIT_TEST(FollowedPolylineDistanceCalculationTest)
double distance = polyline.GetDistanceM(polyline.Begin(), polyline.End());
double masterDistance = MercatorBounds::DistanceOnEarth(kTestDirectedPolyline.Front(),
kTestDirectedPolyline.Back());
- ASSERT_LESS(pow(distance - masterDistance, 2), 0.001, (distance, masterDistance));
+ TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
+ distance = polyline.GetTotalDistanceM();
+ TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
// Test partial length case.
polyline.UpdateProjection(MercatorBounds::RectByCenterXYAndSizeInMeters({3, 0}, 2));
distance = polyline.GetDistanceM(polyline.GetCurrentIter(), polyline.End());
masterDistance = MercatorBounds::DistanceOnEarth(kTestDirectedPolyline.GetPoint(1),
kTestDirectedPolyline.Back());
- ASSERT_LESS(pow(distance - masterDistance, 2), 0.001, (distance, masterDistance));
+ TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
+ distance = polyline.GetDistanceToEndM();
+ TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
// Test point in the middle case.
polyline.UpdateProjection(MercatorBounds::RectByCenterXYAndSizeInMeters({4, 0}, 2));
distance = polyline.GetDistanceM(polyline.GetCurrentIter(), polyline.End());
masterDistance = MercatorBounds::DistanceOnEarth(m2::PointD(4, 0),
kTestDirectedPolyline.Back());
- ASSERT_LESS(pow(distance - masterDistance, 2), 0.001, (distance, masterDistance));
+ TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
+ distance = polyline.GetDistanceToEndM();
+ TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
}
UNIT_TEST(FollowedPolylineDirectionTest)
@@ -98,4 +104,16 @@ UNIT_TEST(FollowedPolylineDirectionTest)
polyline.GetCurrentDirectionPoint(directionPoint, 20);
TEST_EQUAL(directionPoint, testPolyline.GetPoint(2), ());
}
+
+UNIT_TEST(FollowedPolylineGetDistanceFromBeginM)
+{
+ m2::PolylineD testPolyline({{0, 0}, {1, 0}, {2, 0}, {3, 0}, {5, 0}, {6, 0}});
+ FollowedPolyline polyline(testPolyline.Begin(), testPolyline.End());
+ m2::PointD point(4, 0);
+ polyline.UpdateProjection(MercatorBounds::RectByCenterXYAndSizeInMeters(point, 2));
+ double distance = polyline.GetDistanceFromBeginM();
+ double masterDistance = MercatorBounds::DistanceOnEarth(kTestDirectedPolyline.Front(),
+ point);
+ TEST_ALMOST_EQUAL_ULPS(distance, masterDistance, ());
+}
} // namespace routing_test