[routing] Get current direction point enchancement.

This commit is contained in:
Lev Dragunov 2015-08-17 13:23:41 +03:00 committed by Alex Zolotarev
parent d8255ee1b2
commit d84b17f6d3
5 changed files with 36 additions and 7 deletions

View file

@ -2244,7 +2244,6 @@ void Framework::InsertRoute(Route const & route)
return;
}
double mercatorDistance = 0;
vector<double> turnsDistances;
if (m_currentRouterType == RouterType::Vehicle)
{

View file

@ -151,4 +151,18 @@ double FollowedPolyline::GetMercatorDistanceFromBegin() const
return distance;
}
void FollowedPolyline::GetCurrentDirectionPoint(m2::PointD & pt, double toleranceM) const
{
ASSERT(IsValid(), ());
size_t currentIndex = min(m_current.m_ind + 1, m_poly.GetSize() - 1);
m2::PointD point = m_poly.GetPoint(currentIndex);
for (; currentIndex < m_poly.GetSize() - 1; point = m_poly.GetPoint(++currentIndex))
{
if (MercatorBounds::DistanceOnEarth(point, m_current.m_pt) > toleranceM)
break;
}
pt = point;
}
} // namespace routing

View file

@ -26,10 +26,11 @@ public:
double GetMercatorDistanceFromBegin() const;
void GetCurrentDirectionPoint(m2::PointD & pt) const
{
pt = m_poly.GetPoint(min(m_current.m_ind + 1, m_poly.GetSize() - 1));
}
/*! \brief Return next navigation point for direction widgets.
* Returns first geomety point from the polyline after your location if it is farther then
* toleranceM.
*/
void GetCurrentDirectionPoint(m2::PointD & pt, double toleranceM) const;
struct Iter
{

View file

@ -173,9 +173,9 @@ void Route::GetCurrentTurn(double & distanceToTurnMeters, turns::TurnItem & turn
void Route::GetCurrentDirectionPoint(m2::PointD & pt) const
{
if (m_routingSettings.m_keepPedestrianInfo)
m_simplifiedPoly.GetCurrentDirectionPoint(pt);
m_simplifiedPoly.GetCurrentDirectionPoint(pt, kOnEndToleranceM);
else
m_poly.GetCurrentDirectionPoint(pt);
m_poly.GetCurrentDirectionPoint(pt, kOnEndToleranceM);
}
bool Route::MoveIterator(location::GpsInfo const & info) const

View file

@ -83,4 +83,19 @@ UNIT_TEST(FollowedPolylineDistanceCalculationTest)
kTestDirectedPolyline.Back());
ASSERT_LESS(pow(distance - masterDistance, 2), 0.001, (distance, masterDistance));
}
UNIT_TEST(FollowdPolylineDirectionTest)
{
m2::PolylineD testPolyline({{0, 0}, {1.00003, 0}, {1.00003, 1}});
FollowedPolyline polyline(testPolyline.Begin(), testPolyline.End());
TEST_EQUAL(polyline.GetCurrentIter().m_ind, 0, ());
m2::PointD directionPoint;
polyline.GetCurrentDirectionPoint(directionPoint, 20);
TEST_EQUAL(directionPoint, testPolyline.GetPoint(1), ());
polyline.UpdateProjection(MercatorBounds::RectByCenterXYAndSizeInMeters({1.0, 0}, 2));
polyline.GetCurrentDirectionPoint(directionPoint, 0.0001);
TEST_EQUAL(directionPoint, testPolyline.GetPoint(1), ());
polyline.GetCurrentDirectionPoint(directionPoint, 20);
TEST_EQUAL(directionPoint, testPolyline.GetPoint(2), ());
}
} // namespace routing_test