diff options
author | Vladimir Byko-Ianko <v.bykoianko@corp.mail.ru> | 2018-09-19 20:11:12 +0300 |
---|---|---|
committer | Vlad Mihaylenko <vxmihaylenko@gmail.com> | 2018-09-20 18:05:43 +0300 |
commit | 5767b1f71c3ff1890f24d35da77d6e81ed3eb780 (patch) | |
tree | b0682854244e3e607b1f9ccabea3b2adda6ef7cc /routing_common | |
parent | a9d9007eeebf04ac83d7c1f8e70e1b048d087450 (diff) |
Using in city properties for getting speed.
Diffstat (limited to 'routing_common')
-rw-r--r-- | routing_common/routing_common_tests/vehicle_model_test.cpp | 2 | ||||
-rw-r--r-- | routing_common/vehicle_model.cpp | 28 | ||||
-rw-r--r-- | routing_common/vehicle_model.hpp | 5 |
3 files changed, 16 insertions, 19 deletions
diff --git a/routing_common/routing_common_tests/vehicle_model_test.cpp b/routing_common/routing_common_tests/vehicle_model_test.cpp index e897cf0dae..4901349786 100644 --- a/routing_common/routing_common_tests/vehicle_model_test.cpp +++ b/routing_common/routing_common_tests/vehicle_model_test.cpp @@ -67,7 +67,7 @@ void CheckSpeed(initializer_list<uint32_t> const & types, SpeedKMpH && expectedS for (uint32_t t : types) h.Add(t); - TEST_EQUAL(vehicleModel.GetMinTypeSpeed(h), expectedSpeed, ()); + TEST_EQUAL(vehicleModel.GetMinTypeSpeed(h, false /* in city */), expectedSpeed, ()); } void CheckOneWay(initializer_list<uint32_t> const & types, bool expectedValue) diff --git a/routing_common/vehicle_model.cpp b/routing_common/vehicle_model.cpp index f8cf9ed8fa..62d57f5d86 100644 --- a/routing_common/vehicle_model.cpp +++ b/routing_common/vehicle_model.cpp @@ -94,34 +94,34 @@ VehicleModel::SpeedKMpH VehicleModel::GetSpeed(FeatureType & f, bool inCity) con feature::TypesHolder const types(f); RoadAvailability const restriction = GetRoadAvailability(types); - // TODO(bykoianko) If a road is available, a speed according to city status (CityRoads) - // should be returned. if (restriction == RoadAvailability::Available) - return GetMaxSpeed().m_outCity; + return inCity ? GetMaxSpeed().m_inCity : GetMaxSpeed().m_outCity; if (restriction != RoadAvailability::NotAvailable && HasRoadType(types)) - return GetMinTypeSpeed(types); + return GetMinTypeSpeed(types, inCity); return {}; } -VehicleModel::SpeedKMpH VehicleModel::GetMinTypeSpeed(feature::TypesHolder const & types) const +VehicleModel::SpeedKMpH VehicleModel::GetMinTypeSpeed(feature::TypesHolder const & types, bool inCity) const { - // @TODO(bykoianko) Check if there's a feature in city or not and use correct speed. - VehicleModel::SpeedKMpH speed{m_maxSpeed.m_outCity.m_weight * 2.0, m_maxSpeed.m_outCity.m_eta * 2.0}; + double const maxSpeedWeight = inCity ? m_maxSpeed.m_inCity.m_weight : m_maxSpeed.m_outCity.m_weight; + double const maxEtaWeight = inCity ? m_maxSpeed.m_inCity.m_eta : m_maxSpeed.m_outCity.m_eta; + VehicleModel::SpeedKMpH speed{maxSpeedWeight * 2.0, maxEtaWeight * 2.0}; // Decreasing speed factor based on road surface (cover). VehicleModel::SpeedFactor factor; for (uint32_t t : types) { - // @TODO(bykoianko) Check if there's a feature in city or not and use correct speed. uint32_t const type = ftypes::BaseChecker::PrepareToMatch(t, 2); auto const itHighway = m_highwayTypes.find(type); if (itHighway != m_highwayTypes.cend()) - speed = Pick<min>(speed, itHighway->second.GetSpeed()); + speed = Pick<min>(speed, itHighway->second.GetSpeed(inCity)); auto const addRoadInfoIter = FindRoadType(t); - // @TODO(bykoianko) Check if there's a feature in city or not and use correct speed. if (addRoadInfoIter != m_addRoadTypes.cend()) - speed = Pick<min>(speed, addRoadInfoIter->m_speed.m_outCity); + { + speed = Pick<min>( + speed, inCity ? addRoadInfoIter->m_speed.m_inCity : addRoadInfoIter->m_speed.m_outCity); + } auto const itFactor = find_if(m_surfaceFactors.cbegin(), m_surfaceFactors.cend(), [t](TypeFactor const & v) { return v.m_type == t; }); @@ -135,12 +135,10 @@ VehicleModel::SpeedKMpH VehicleModel::GetMinTypeSpeed(feature::TypesHolder const CHECK_GREATER_OR_EQUAL(factor.m_eta, 0.0, ()); VehicleModel::SpeedKMpH ret; - // @TODO(bykoianko) Check if there's a feature in city or not and use correct speed. - if (speed.m_weight <= m_maxSpeed.m_outCity.m_weight) + if (speed.m_weight <= maxSpeedWeight) ret.m_weight = speed.m_weight * factor.m_weight; - // @TODO(bykoianko) Check if there's a feature in city or not and use correct speed. - if (speed.m_eta <= m_maxSpeed.m_outCity.m_eta) + if (speed.m_eta <= maxEtaWeight) ret.m_eta = speed.m_eta * factor.m_eta; return ret; diff --git a/routing_common/vehicle_model.hpp b/routing_common/vehicle_model.hpp index 31d01a2b70..f9f31afc5f 100644 --- a/routing_common/vehicle_model.hpp +++ b/routing_common/vehicle_model.hpp @@ -202,7 +202,7 @@ protected: bool HasPassThroughType(feature::TypesHolder const & types) const; - SpeedKMpH GetMinTypeSpeed(feature::TypesHolder const & types) const; + SpeedKMpH GetMinTypeSpeed(feature::TypesHolder const & types, bool inCity) const; InOutCitySpeedKMpH m_maxSpeed; @@ -222,8 +222,7 @@ private: public: RoadLimits(InOutCitySpeedKMpH const & speed, bool isPassThroughAllowed); - // @TODO() GetSpeed() should return speed in city and outside. - SpeedKMpH const & GetSpeed() const { return m_speed.m_outCity; }; + SpeedKMpH const & GetSpeed(bool inCity) const { return inCity ? m_speed.m_inCity : m_speed.m_outCity; }; bool IsPassThroughAllowed() const { return m_isPassThroughAllowed; }; bool operator==(RoadLimits const & rhs) const { |