diff --git a/routing_common/bicycle_model.cpp b/routing_common/bicycle_model.cpp index c575cf7dde..ea365210b8 100644 --- a/routing_common/bicycle_model.cpp +++ b/routing_common/bicycle_model.cpp @@ -213,9 +213,9 @@ bool BicycleModel::IsBicycleOnedir(feature::TypesHolder const & types) const return types.Has(m_onedirBicycleType); } -SpeedKMpH BicycleModel::GetSpeed(FeatureType & f, SpeedParams const & speedParams) const +SpeedKMpH BicycleModel::GetTypeSpeed(feature::TypesHolder const & types, SpeedParams const & speedParams) const { - return VehicleModel::GetSpeedWihtoutMaxspeed(f, speedParams); + return GetTypeSpeedImpl(types, speedParams, false /* isCar */); } bool BicycleModel::IsOneWay(FeatureType & f) const diff --git a/routing_common/bicycle_model.hpp b/routing_common/bicycle_model.hpp index 2020f89830..c03871f323 100644 --- a/routing_common/bicycle_model.hpp +++ b/routing_common/bicycle_model.hpp @@ -13,7 +13,7 @@ public: BicycleModel(VehicleModel::LimitsInitList const & limits, HighwayBasedSpeeds const & speeds); /// VehicleModelInterface overrides: - SpeedKMpH GetSpeed(FeatureType & f, SpeedParams const & speedParams) const override; + SpeedKMpH GetTypeSpeed(feature::TypesHolder const & types, SpeedParams const & speedParams) const override; bool IsOneWay(FeatureType & f) const override; SpeedKMpH const & GetOffroadSpeed() const override; diff --git a/routing_common/car_model.cpp b/routing_common/car_model.cpp index 2a9d4abe0c..36fe66df97 100644 --- a/routing_common/car_model.cpp +++ b/routing_common/car_model.cpp @@ -112,9 +112,14 @@ CarModel::CarModel(VehicleModel::LimitsInitList const & roadLimits) ASSERT_EQUAL(kHighwayBasedSpeeds.size(), kHighwayBasedFactors.size(), ()); ASSERT_EQUAL(kHighwayBasedSpeeds.size(), car_model::kDefaultOptions.size(), ()); + std::vector hwtagYesCar = {"hwtag", "yescar"}; auto const & cl = classif(); + m_noType = cl.GetTypeByPath({"hwtag", "nocar"}); - m_yesType = cl.GetTypeByPath({"hwtag", "yescar"}); + m_yesType = cl.GetTypeByPath(hwtagYesCar); + + // Set small track speed if highway is not in kHighwayBasedSpeeds (path, pedestrian), but marked as yescar. + AddAdditionalRoadTypes(cl, {{ std::move(hwtagYesCar), kHighwayBasedSpeeds.Get(HighwayType::HighwayTrack) }}); // Set max possible (reasonable) car speed. See EdgeEstimator::CalcHeuristic. SpeedKMpH constexpr kMaxCarSpeedKMpH(200.0); @@ -122,6 +127,11 @@ CarModel::CarModel(VehicleModel::LimitsInitList const & roadLimits) m_maxModelSpeed = kMaxCarSpeedKMpH; } +SpeedKMpH CarModel::GetTypeSpeed(feature::TypesHolder const & types, SpeedParams const & speedParams) const +{ + return GetTypeSpeedImpl(types, speedParams, true /* isCar */); +} + SpeedKMpH const & CarModel::GetOffroadSpeed() const { return car_model::kSpeedOffroadKMpH; } // static diff --git a/routing_common/car_model.hpp b/routing_common/car_model.hpp index 8dab271a64..80d1711bcb 100644 --- a/routing_common/car_model.hpp +++ b/routing_common/car_model.hpp @@ -11,7 +11,8 @@ public: CarModel(); explicit CarModel(LimitsInitList const & roadLimits); - // VehicleModelInterface overrides: + /// VehicleModelInterface overrides: + SpeedKMpH GetTypeSpeed(feature::TypesHolder const & types, SpeedParams const & speedParams) const override; SpeedKMpH const & GetOffroadSpeed() const override; static CarModel const & AllLimitsInstance(); diff --git a/routing_common/pedestrian_model.cpp b/routing_common/pedestrian_model.cpp index f0ae6b86f5..424d3b79e8 100644 --- a/routing_common/pedestrian_model.cpp +++ b/routing_common/pedestrian_model.cpp @@ -154,9 +154,9 @@ PedestrianModel::PedestrianModel(VehicleModel::LimitsInitList const & speedLimit m_maxModelSpeed = kMaxPedestrianSpeedKMpH; } -SpeedKMpH PedestrianModel::GetSpeed(FeatureType & f, SpeedParams const & speedParams) const +SpeedKMpH PedestrianModel::GetTypeSpeed(feature::TypesHolder const & types, SpeedParams const & speedParams) const { - return VehicleModel::GetSpeedWihtoutMaxspeed(f, speedParams); + return GetTypeSpeedImpl(types, speedParams, false /* isCar */); } SpeedKMpH const & PedestrianModel::GetOffroadSpeed() const { return pedestrian_model::kSpeedOffroadKMpH; } diff --git a/routing_common/pedestrian_model.hpp b/routing_common/pedestrian_model.hpp index a2faa26e4c..c5918a3287 100644 --- a/routing_common/pedestrian_model.hpp +++ b/routing_common/pedestrian_model.hpp @@ -12,7 +12,7 @@ public: explicit PedestrianModel(VehicleModel::LimitsInitList const & speedLimits); /// VehicleModelInterface overrides: - SpeedKMpH GetSpeed(FeatureType & f, SpeedParams const & speedParams) const override; + SpeedKMpH GetTypeSpeed(feature::TypesHolder const & types, SpeedParams const & speedParams) const override; bool IsOneWay(FeatureType &) const override { return false; } SpeedKMpH const & GetOffroadSpeed() const override; diff --git a/routing_common/routing_common_tests/vehicle_model_test.cpp b/routing_common/routing_common_tests/vehicle_model_test.cpp index bd3c420bab..17fa403b41 100644 --- a/routing_common/routing_common_tests/vehicle_model_test.cpp +++ b/routing_common/routing_common_tests/vehicle_model_test.cpp @@ -86,6 +86,11 @@ public: { } + SpeedKMpH GetTypeSpeed(feature::TypesHolder const & types, SpeedParams const & params) const override + { + return GetTypeSpeedImpl(types, params, true /* isCar */); + } + // We are not going to use offroad routing in these tests. SpeedKMpH const & GetOffroadSpeed() const override { diff --git a/routing_common/vehicle_model.cpp b/routing_common/vehicle_model.cpp index 8998a9ba04..dac172d088 100644 --- a/routing_common/vehicle_model.cpp +++ b/routing_common/vehicle_model.cpp @@ -78,12 +78,6 @@ uint32_t VehicleModel::PrepareToMatchType(uint32_t type) const return type; } -SpeedKMpH VehicleModel::GetSpeed(FeatureType & f, SpeedParams const & speedParams) const -{ - feature::TypesHolder const types(f); - return IsRoadImpl(types) ? GetTypeSpeed(types, speedParams) : SpeedKMpH(); -} - std::optional VehicleModel::GetHighwayType(FeatureType & f) const { feature::TypesHolder const types(f); @@ -138,7 +132,7 @@ void VehicleModel::GetAdditionalRoadSpeed(uint32_t type, bool isCityRoad, } } -SpeedKMpH VehicleModel::GetTypeSpeed(feature::TypesHolder const & types, SpeedParams const & params) const +SpeedKMpH VehicleModel::GetTypeSpeedImpl(feature::TypesHolder const & types, SpeedParams const & params, bool isCar) const { bool const isCityRoad = params.m_inCity; optional hwType; @@ -158,14 +152,15 @@ SpeedKMpH VehicleModel::GetTypeSpeed(feature::TypesHolder const & types, SpeedPa SpeedKMpH speed; if (hwType) { - if (params.m_maxspeed.IsValid()) + if (isCar && params.m_maxspeed.IsValid()) { MaxspeedType const s = params.m_maxspeed.GetSpeedKmPH(params.m_forward); ASSERT(s != kInvalidSpeed, (*hwType, params.m_forward, params.m_maxspeed)); speed = {static_cast(s)}; } - else if (additionalRoadSpeed) + else if (!isCar && additionalRoadSpeed) { + // Take additional speed for bicycle and pedestrian only. Car should take highway speed first. speed = *additionalRoadSpeed; } else @@ -194,22 +189,14 @@ SpeedKMpH VehicleModel::GetTypeSpeed(feature::TypesHolder const & types, SpeedPa else { ASSERT(additionalRoadSpeed, ()); - speed = *additionalRoadSpeed; + if (additionalRoadSpeed) + speed = *additionalRoadSpeed; } ASSERT(!(m_maxModelSpeed < speed), (speed, m_maxModelSpeed)); return speed * surfaceFactor; } -SpeedKMpH VehicleModel::GetSpeedWihtoutMaxspeed(FeatureType & f, SpeedParams params) const -{ - // This function used for bicyle and pedestring GetSpeed implementation, so saved speeds are not applyable here. - params.m_maxspeed = {}; - params.m_defSpeedKmPH = kInvalidSpeed; - - return VehicleModel::GetSpeed(f, params); -} - bool VehicleModel::IsOneWay(FeatureType & f) const { return HasOneWayType(feature::TypesHolder(f)); diff --git a/routing_common/vehicle_model.hpp b/routing_common/vehicle_model.hpp index 3c2af114d7..0c36741e2c 100644 --- a/routing_common/vehicle_model.hpp +++ b/routing_common/vehicle_model.hpp @@ -2,6 +2,8 @@ #include "routing_common/maxspeed_conversion.hpp" +#include "indexer/feature_data.hpp" + #include "base/small_map.hpp" #include @@ -17,8 +19,6 @@ class Classificator; class FeatureType; -namespace feature { class TypesHolder; } - namespace routing { double constexpr kNotUsed = std::numeric_limits::max(); @@ -276,9 +276,15 @@ public: VehicleModel(Classificator const & classif, LimitsInitList const & featureTypeLimits, SurfaceInitList const & featureTypeSurface, HighwayBasedInfo const & info); + virtual SpeedKMpH GetTypeSpeed(feature::TypesHolder const & types, SpeedParams const & params) const = 0; + /// @name VehicleModelInterface overrides. /// @{ - SpeedKMpH GetSpeed(FeatureType & f, SpeedParams const & speedParams) const override; + SpeedKMpH GetSpeed(FeatureType & f, SpeedParams const & speedParams) const override + { + return GetTypeSpeed(feature::TypesHolder(f), speedParams); + } + std::optional GetHighwayType(FeatureType & f) const override; double GetMaxWeightSpeed() const override; bool IsOneWay(FeatureType & f) const override; @@ -300,8 +306,6 @@ public: return false; } - SpeedKMpH GetTypeSpeed(feature::TypesHolder const & types, SpeedParams const & params) const; - bool EqualsForTests(VehicleModel const & rhs) const { return (m_roadTypes == rhs.m_roadTypes) && (m_addRoadTypes == rhs.m_addRoadTypes) && @@ -321,12 +325,12 @@ protected: uint32_t m_yesType, m_noType; bool IsRoadImpl(feature::TypesHolder const & types) const; + SpeedKMpH GetTypeSpeedImpl(feature::TypesHolder const & types, SpeedParams const & params, bool isCar) const; + void AddAdditionalRoadTypes(Classificator const & classif, AdditionalRoadsList const & roads); uint32_t PrepareToMatchType(uint32_t type) const; - SpeedKMpH GetSpeedWihtoutMaxspeed(FeatureType & f, SpeedParams params) const; - /// \brief Maximum within all the speed limits set in a model (car model, bicycle model and so on). /// Do not mix with maxspeed value tag, which defines maximum legal speed on a feature. SpeedKMpH m_maxModelSpeed;