forked from organicmaps/organicmaps
Reduce speedcam geometry index reading.
This commit is contained in:
parent
e481c43ded
commit
2bc9bf1191
3 changed files with 24 additions and 18 deletions
|
@ -41,21 +41,12 @@ double constexpr kInvalidSpeedCameraDistance = -1;
|
|||
|
||||
namespace routing
|
||||
{
|
||||
struct SpeedCameraRestriction
|
||||
{
|
||||
uint32_t m_index; // Index of a polyline point where camera is located.
|
||||
uint8_t m_maxSpeedKmH; // Maximum speed allowed by the camera.
|
||||
|
||||
SpeedCameraRestriction(uint32_t index, uint8_t maxSpeed) : m_index(index), m_maxSpeedKmH(maxSpeed) {}
|
||||
};
|
||||
|
||||
RoutingSession::RoutingSession()
|
||||
: m_router(nullptr),
|
||||
m_route(string()),
|
||||
m_state(RoutingNotActive),
|
||||
m_endPoint(m2::PointD::Zero()),
|
||||
m_lastWarnedSpeedCameraIndex(0),
|
||||
m_lastCheckedCameraIndex(0),
|
||||
m_speedWarningSignal(false),
|
||||
m_passedDistanceOnRouteMeters(0.0)
|
||||
{
|
||||
|
@ -144,7 +135,7 @@ void RoutingSession::Reset()
|
|||
|
||||
m_passedDistanceOnRouteMeters = 0.0;
|
||||
m_lastWarnedSpeedCameraIndex = 0;
|
||||
m_lastCheckedCameraIndex = 0;
|
||||
m_lastCheckedCamera = SpeedCameraRestriction();
|
||||
m_speedWarningSignal = false;
|
||||
}
|
||||
|
||||
|
@ -354,7 +345,7 @@ void RoutingSession::AssignRoute(Route & route, IRouter::ResultCode e)
|
|||
route.SetRoutingSettings(m_routingSettings);
|
||||
m_route.Swap(route);
|
||||
m_lastWarnedSpeedCameraIndex = 0;
|
||||
m_lastCheckedCameraIndex = 0;
|
||||
m_lastCheckedCamera = SpeedCameraRestriction();
|
||||
}
|
||||
|
||||
void RoutingSession::SetRouter(unique_ptr<IRouter> && router,
|
||||
|
@ -437,18 +428,26 @@ string RoutingSession::GetTurnNotificationsLocale() const
|
|||
double RoutingSession::GetDistanceToCurrentCamM(SpeedCameraRestriction & camera, Index const & index)
|
||||
{
|
||||
auto const & m_poly = m_route.GetFollowedPolyline();
|
||||
size_t const currentIndex = max(m_poly.GetCurrentIter().m_ind, m_lastCheckedCameraIndex);
|
||||
auto const & currentIter = m_poly.GetCurrentIter();
|
||||
if (currentIter.m_ind < m_lastCheckedCamera.m_index &&
|
||||
m_lastCheckedCamera.m_index < m_poly.GetPolyline().GetSize())
|
||||
{
|
||||
camera = m_lastCheckedCamera;
|
||||
return m_poly.GetDistanceM(currentIter, m_poly.GetIterToIndex(camera.m_index));
|
||||
}
|
||||
size_t const currentIndex = max(static_cast<size_t>(currentIter.m_ind),
|
||||
static_cast<size_t>(m_lastCheckedCamera.m_index) + 1);
|
||||
for (size_t i = currentIndex; i < m_poly.GetPolyline().GetSize(); ++i)
|
||||
{
|
||||
uint8_t speed = CheckCameraInPoint(m_poly.GetPolyline().GetPoint(i), index);
|
||||
if (speed != kNoSpeedCamera)
|
||||
{
|
||||
camera = SpeedCameraRestriction(static_cast<uint32_t>(i), speed);
|
||||
m_lastCheckedCameraIndex = i;
|
||||
return m_poly.GetDistanceM(m_poly.GetCurrentIter(), m_poly.GetIterToIndex(i));
|
||||
m_lastCheckedCamera = camera;
|
||||
return m_poly.GetDistanceM(currentIter, m_poly.GetIterToIndex(i));
|
||||
}
|
||||
}
|
||||
m_lastCheckedCameraIndex = m_poly.GetPolyline().GetSize();
|
||||
m_lastCheckedCamera.m_index = m_poly.GetPolyline().GetSize();
|
||||
return kInvalidSpeedCameraDistance;
|
||||
}
|
||||
} // namespace routing
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "base/deferred_task.hpp"
|
||||
#include "base/mutex.hpp"
|
||||
|
||||
#include "std/limits.hpp"
|
||||
#include "std/unique_ptr.hpp"
|
||||
|
||||
namespace location
|
||||
|
@ -23,7 +24,14 @@ class RouteMatchingInfo;
|
|||
|
||||
namespace routing
|
||||
{
|
||||
struct SpeedCameraRestriction;
|
||||
struct SpeedCameraRestriction
|
||||
{
|
||||
uint32_t m_index; // Index of a polyline point where camera is located.
|
||||
uint8_t m_maxSpeedKmH; // Maximum speed allowed by the camera.
|
||||
|
||||
SpeedCameraRestriction(uint32_t index, uint8_t maxSpeed) : m_index(index), m_maxSpeedKmH(maxSpeed) {}
|
||||
SpeedCameraRestriction() : m_index(0), m_maxSpeedKmH(numeric_limits<uint8_t>::max()) {}
|
||||
};
|
||||
|
||||
class RoutingSession
|
||||
{
|
||||
|
@ -132,7 +140,7 @@ private:
|
|||
State m_state;
|
||||
m2::PointD m_endPoint;
|
||||
size_t m_lastWarnedSpeedCameraIndex;
|
||||
size_t m_lastCheckedCameraIndex;
|
||||
SpeedCameraRestriction m_lastCheckedCamera;
|
||||
// TODO (ldragunov) Rewrite UI interop to message queue and avoid mutable.
|
||||
/// This field is mutable because it's modified in a constant getter. Note that the notification
|
||||
/// about camera will be sent at most once.
|
||||
|
|
|
@ -50,7 +50,6 @@ uint8_t CheckCameraInPoint(m2::PointD const & point, Index const & index)
|
|||
if (!ftypes::IsSpeedCamChecker::Instance()(hl))
|
||||
return;
|
||||
|
||||
ft.ParseGeometry(FeatureType::BEST_GEOMETRY);
|
||||
if (my::AlmostEqualAbs(ft.GetCenter().x, point.x, kCoordinateEqualityDelta) &&
|
||||
my::AlmostEqualAbs(ft.GetCenter().y, point.y, kCoordinateEqualityDelta))
|
||||
speedLimit = ReadCameraRestriction(ft);
|
||||
|
|
Loading…
Add table
Reference in a new issue