PR fixes.

This commit is contained in:
Lev Dragunov 2015-11-03 18:13:26 +03:00
parent d17820b9d7
commit 005d6674a4
2 changed files with 11 additions and 15 deletions

View file

@ -138,7 +138,7 @@ void RoutingSession::Reset()
m_passedDistanceOnRouteMeters = 0.0;
m_lastWarnedSpeedCameraIndex = 0;
m_lastCheckedSpeedCameraIndex = 0;
m_lastCheckedCamera = SpeedCameraRestriction();
m_lastFoundCamera = SpeedCameraRestriction();
m_speedWarningSignal = false;
}
@ -335,7 +335,7 @@ void RoutingSession::AssignRoute(Route & route, IRouter::ResultCode e)
m_route.Swap(route);
m_lastWarnedSpeedCameraIndex = 0;
m_lastCheckedSpeedCameraIndex = 0;
m_lastCheckedCamera = SpeedCameraRestriction();
m_lastFoundCamera = SpeedCameraRestriction();
}
void RoutingSession::SetRouter(unique_ptr<IRouter> && router,
@ -428,29 +428,24 @@ double RoutingSession::GetDistanceToCurrentCamM(SpeedCameraRestriction & camera,
{
auto const & m_poly = m_route.GetFollowedPolyline();
auto const & currentIter = m_poly.GetCurrentIter();
if (currentIter.m_ind < m_lastCheckedCamera.m_index &&
m_lastCheckedCamera.m_index < m_poly.GetPolyline().GetSize())
if (currentIter.m_ind < m_lastFoundCamera.m_index &&
m_lastFoundCamera.m_index < m_poly.GetPolyline().GetSize())
{
camera = m_lastCheckedCamera;
camera = m_lastFoundCamera;
return m_poly.GetDistanceM(currentIter, m_poly.GetIterToIndex(camera.m_index));
}
size_t const currentIndex = max(max(currentIter.m_ind, m_lastCheckedSpeedCameraIndex),
m_lastCheckedCamera.m_index + 1);
size_t moveAwayCounter = 0;
for (m_lastCheckedSpeedCameraIndex = currentIndex; m_lastCheckedSpeedCameraIndex < m_poly.GetPolyline().GetSize(); ++m_lastCheckedSpeedCameraIndex)
size_t const currentIndex = max(currentIter.m_ind, m_lastCheckedSpeedCameraIndex + 1);
size_t const upperBound = min(m_poly.GetPolyline().GetSize(), currentIndex + kSpeedCameraLookAheadCount);
for (m_lastCheckedSpeedCameraIndex = currentIndex; m_lastCheckedSpeedCameraIndex < upperBound; ++m_lastCheckedSpeedCameraIndex)
{
uint8_t speed = CheckCameraInPoint(m_poly.GetPolyline().GetPoint(m_lastCheckedSpeedCameraIndex), index);
if (speed != kNoSpeedCamera)
{
camera = SpeedCameraRestriction(static_cast<uint32_t>(m_lastCheckedSpeedCameraIndex), speed);
m_lastCheckedCamera = camera;
m_lastFoundCamera = camera;
return m_poly.GetDistanceM(currentIter, m_poly.GetIterToIndex(m_lastCheckedSpeedCameraIndex));
}
++moveAwayCounter;
if (moveAwayCounter > kSpeedCameraLookAheadCount)
return kInvalidSpeedCameraDistance;
}
m_lastCheckedCamera.m_index = m_poly.GetPolyline().GetSize();
return kInvalidSpeedCameraDistance;
}
} // namespace routing

View file

@ -147,7 +147,8 @@ private:
State m_state;
m2::PointD m_endPoint;
size_t m_lastWarnedSpeedCameraIndex;
SpeedCameraRestriction m_lastCheckedCamera;
SpeedCameraRestriction m_lastFoundCamera;
// Index of a last point on a route checked for a speed camera.
size_t m_lastCheckedSpeedCameraIndex;
// TODO (ldragunov) Rewrite UI interop to message queue and avoid mutable.