Format all C++ and Java code via clang-format

Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
Konstantin Pastbin
2025-08-17 14:32:37 +07:00
parent 9f0290c0ec
commit bfffa1fff4
2169 changed files with 56441 additions and 64188 deletions

View File

@@ -90,8 +90,7 @@ VehicleModel::LimitsInitList const kDefaultOptions = {
{HighwayType::HighwayPedestrian, true},
{HighwayType::HighwayFootway, true},
{HighwayType::ManMadePier, true},
{HighwayType::RouteFerry, true}
};
{HighwayType::RouteFerry, true}};
// Same as defaults except trunk and trunk_link are not allowed
VehicleModel::LimitsInitList NoTrunk()
@@ -99,10 +98,8 @@ VehicleModel::LimitsInitList NoTrunk()
VehicleModel::LimitsInitList res;
res.reserve(kDefaultOptions.size() - 2);
for (auto const & e : kDefaultOptions)
{
if (e.m_type != HighwayType::HighwayTrunk && e.m_type != HighwayType::HighwayTrunkLink)
res.push_back(e);
}
return res;
}
@@ -163,38 +160,32 @@ VehicleModel::LimitsInitList UkraineOptions()
{
auto res = NoTrunk();
for (auto & e : res)
{
if (e.m_type == HighwayType::HighwayLivingStreet || e.m_type == HighwayType::HighwayService)
e.m_isPassThroughAllowed = false;
}
return res;
}
VehicleModel::SurfaceInitList const kBicycleSurface = {
// {{surfaceType}, {weightFactor, etaFactor}}
{{"psurface", "paved_good"}, {1.0, 1.0}},
{{"psurface", "paved_bad"}, {0.8, 0.8}},
{{"psurface", "unpaved_good"}, {0.9, 0.9}},
{{"psurface", "unpaved_bad"}, {0.3, 0.3}},
// No dedicated cycleway doesn't mean that bicycle is not allowed, just lower weight.
// If nocycleway is tagged explicitly then there is no cycling infra for sure.
// Otherwise there is a small chance cycling infra is present though not mapped?
/// @todo(pastk): this heuristic is controversial, maybe remove completely?
{{"hwtag", "nocycleway"}, {0.95, 0.95}},
// {{surfaceType}, {weightFactor, etaFactor}}
{{"psurface", "paved_good"}, {1.0, 1.0}},
{{"psurface", "paved_bad"}, {0.8, 0.8}},
{{"psurface", "unpaved_good"}, {0.9, 0.9}},
{{"psurface", "unpaved_bad"}, {0.3, 0.3}},
// No dedicated cycleway doesn't mean that bicycle is not allowed, just lower weight.
// If nocycleway is tagged explicitly then there is no cycling infra for sure.
// Otherwise there is a small chance cycling infra is present though not mapped?
/// @todo(pastk): this heuristic is controversial, maybe remove completely?
{{"hwtag", "nocycleway"}, {0.95, 0.95}},
};
} // namespace bicycle_model
namespace routing
{
BicycleModel::BicycleModel()
: BicycleModel(bicycle_model::kDefaultOptions)
{
}
BicycleModel::BicycleModel() : BicycleModel(bicycle_model::kDefaultOptions) {}
BicycleModel::BicycleModel(VehicleModel::LimitsInitList const & limits)
: BicycleModel(limits, bicycle_model::kDefaultSpeeds)
{
}
{}
BicycleModel::BicycleModel(VehicleModel::LimitsInitList const & limits, HighwayBasedSpeeds const & speeds)
: VehicleModel(classif(), limits, bicycle_model::kBicycleSurface, {speeds, bicycle_model::kDefaultFactors})
@@ -214,7 +205,7 @@ BicycleModel::BicycleModel(VehicleModel::LimitsInitList const & limits, HighwayB
// Assign 90% of max cycleway speed for bicycle=yes to keep choosing most preferred cycleway.
auto const yesSpeed = kDefaultSpeeds.Get(HighwayType::HighwayCycleway).m_inCity * 0.9;
AddAdditionalRoadTypes(cl, {{ std::move(hwtagYesBicycle), InOutCitySpeedKMpH(yesSpeed) }});
AddAdditionalRoadTypes(cl, {{std::move(hwtagYesBicycle), InOutCitySpeedKMpH(yesSpeed)}});
// Update max speed with possible ferry transfer and bicycle speed downhill.
// See EdgeEstimator::CalcHeuristic, GetBicycleClimbPenalty.
@@ -249,7 +240,10 @@ bool BicycleModel::IsOneWay(FeatureTypes const & types) const
return VehicleModel::IsOneWay(types);
}
SpeedKMpH const & BicycleModel::GetOffroadSpeed() const { return bicycle_model::kSpeedOffroadKMpH; }
SpeedKMpH const & BicycleModel::GetOffroadSpeed() const
{
return bicycle_model::kSpeedOffroadKMpH;
}
// If one of feature types will be disabled for bicycles, features of this type will be simplified
// in generator. Look FeatureBuilder1::IsRoad() for more details.
@@ -266,8 +260,7 @@ SpeedKMpH BicycleModel::DismountSpeed()
return bicycle_model::kSpeedDismountKMpH;
}
BicycleModelFactory::BicycleModelFactory(
CountryParentNameGetterFn const & countryParentNameGetterFn)
BicycleModelFactory::BicycleModelFactory(CountryParentNameGetterFn const & countryParentNameGetterFn)
: VehicleModelFactory(countryParentNameGetterFn)
{
using namespace bicycle_model;
@@ -295,8 +288,9 @@ BicycleModelFactory::BicycleModelFactory(
m_models["Philippines"] = make_shared<BicycleModel>(AllAllowed(), NormalPedestrianSpeed());
m_models["Poland"] = make_shared<BicycleModel>(NoTrunk());
m_models["Romania"] = make_shared<BicycleModel>(AllAllowed());
// Note. Despite the fact that according to https://wiki.openstreetmap.org/wiki/OSM_tags_for_routing/Access-Restrictions
// passing through service and living_street with a bicycle is prohibited it's allowed according to Russian traffic rules.
// Note. Despite the fact that according to
// https://wiki.openstreetmap.org/wiki/OSM_tags_for_routing/Access-Restrictions passing through service and
// living_street with a bicycle is prohibited it's allowed according to Russian traffic rules.
m_models["Russian Federation"] = make_shared<BicycleModel>(kDefaultOptions, NormalPedestrianAndFootwaySpeed());
m_models["Slovakia"] = make_shared<BicycleModel>(NoTrunk());
m_models["Spain"] = make_shared<BicycleModel>(NoTrunk(), NormalPedestrianSpeed());
@@ -306,4 +300,4 @@ BicycleModelFactory::BicycleModelFactory(
m_models["United Kingdom"] = make_shared<BicycleModel>(AllAllowed());
m_models["United States of America"] = make_shared<BicycleModel>(AllAllowed(), NormalPedestrianSpeed());
}
} // routing
} // namespace routing

View File

@@ -23,45 +23,31 @@ SpeedKMpH constexpr kSpeedOffroadKMpH = {0.01 /* weight */, kNotUsed /* eta */};
VehicleModel::LimitsInitList const kDefaultOptions = {
// {HighwayType, passThroughAllowed}
{HighwayType::HighwayMotorway, true},
{HighwayType::HighwayMotorwayLink, true},
{HighwayType::HighwayTrunk, true},
{HighwayType::HighwayTrunkLink, true},
{HighwayType::HighwayPrimary, true},
{HighwayType::HighwayPrimaryLink, true},
{HighwayType::HighwaySecondary, true},
{HighwayType::HighwaySecondaryLink, true},
{HighwayType::HighwayTertiary, true},
{HighwayType::HighwayTertiaryLink, true},
{HighwayType::HighwayResidential, true},
{HighwayType::HighwayUnclassified, true},
{HighwayType::HighwayService, true},
{HighwayType::HighwayLivingStreet, true},
{HighwayType::HighwayRoad, true},
{HighwayType::HighwayTrack, true},
{HighwayType::RouteShuttleTrain, true},
{HighwayType::RouteFerry, true},
{HighwayType::ManMadePier, true}
};
{HighwayType::HighwayMotorway, true}, {HighwayType::HighwayMotorwayLink, true},
{HighwayType::HighwayTrunk, true}, {HighwayType::HighwayTrunkLink, true},
{HighwayType::HighwayPrimary, true}, {HighwayType::HighwayPrimaryLink, true},
{HighwayType::HighwaySecondary, true}, {HighwayType::HighwaySecondaryLink, true},
{HighwayType::HighwayTertiary, true}, {HighwayType::HighwayTertiaryLink, true},
{HighwayType::HighwayResidential, true}, {HighwayType::HighwayUnclassified, true},
{HighwayType::HighwayService, true}, {HighwayType::HighwayLivingStreet, true},
{HighwayType::HighwayRoad, true}, {HighwayType::HighwayTrack, true},
{HighwayType::RouteShuttleTrain, true}, {HighwayType::RouteFerry, true},
{HighwayType::ManMadePier, true}};
VehicleModel::LimitsInitList NoPassThroughLivingStreet()
{
auto res = kDefaultOptions;
for (auto & e : res)
{
if (e.m_type == HighwayType::HighwayLivingStreet)
e.m_isPassThroughAllowed = false;
}
return res;
}
VehicleModel::LimitsInitList NoPassThroughService(VehicleModel::LimitsInitList res = kDefaultOptions)
{
for (auto & e : res)
{
if (e.m_type == HighwayType::HighwayService)
e.m_isPassThroughAllowed = false;
}
return res;
}
@@ -70,10 +56,8 @@ VehicleModel::LimitsInitList NoTrack()
VehicleModel::LimitsInitList res;
res.reserve(kDefaultOptions.size() - 1);
for (auto const & e : kDefaultOptions)
{
if (e.m_type != HighwayType::HighwayTrack)
res.push_back(e);
}
return res;
}
@@ -81,29 +65,24 @@ VehicleModel::LimitsInitList NoPassThroughTrack()
{
auto res = kDefaultOptions;
for (auto & e : res)
{
if (e.m_type == HighwayType::HighwayTrack)
e.m_isPassThroughAllowed = false;
}
return res;
}
/// @todo Should make some compare constrains (like in CarModel_TrackVsGravelTertiary test)
/// to better fit these factors with reality. I have no idea, how they were set.
VehicleModel::SurfaceInitList const kCarSurface = {
// {{surfaceType, surfaceType}, {weightFactor, etaFactor}}
{{"psurface", "paved_good"}, {1.0, 1.0}},
{{"psurface", "paved_bad"}, {0.6, 0.7}},
{{"psurface", "unpaved_good"}, {0.4, 0.7}},
{{"psurface", "unpaved_bad"}, {0.2, 0.3}}
};
// {{surfaceType, surfaceType}, {weightFactor, etaFactor}}
{{"psurface", "paved_good"}, {1.0, 1.0}},
{{"psurface", "paved_bad"}, {0.6, 0.7}},
{{"psurface", "unpaved_good"}, {0.4, 0.7}},
{{"psurface", "unpaved_bad"}, {0.2, 0.3}}};
} // namespace car_model
namespace routing
{
CarModel::CarModel() : CarModel(car_model::kDefaultOptions)
{
}
CarModel::CarModel() : CarModel(car_model::kDefaultOptions) {}
CarModel::CarModel(VehicleModel::LimitsInitList const & roadLimits)
: VehicleModel(classif(), roadLimits, car_model::kCarSurface, {kHighwayBasedSpeeds, kHighwayBasedFactors})
@@ -118,7 +97,7 @@ CarModel::CarModel(VehicleModel::LimitsInitList const & roadLimits)
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) }});
AddAdditionalRoadTypes(cl, {{std::move(hwtagYesCar), kHighwayBasedSpeeds.Get(HighwayType::HighwayTrack)}});
// Set max possible (reasonable) car speed. See EdgeEstimator::CalcHeuristic.
SpeedKMpH constexpr kMaxCarSpeedKMpH(200.0);
@@ -131,7 +110,10 @@ SpeedKMpH CarModel::GetSpeed(FeatureTypes const & types, SpeedParams const & spe
return GetTypeSpeedImpl(types, speedParams, true /* isCar */);
}
SpeedKMpH const & CarModel::GetOffroadSpeed() const { return car_model::kSpeedOffroadKMpH; }
SpeedKMpH const & CarModel::GetOffroadSpeed() const
{
return car_model::kSpeedOffroadKMpH;
}
// static
CarModel const & CarModel::AllLimitsInstance()
@@ -141,10 +123,16 @@ CarModel const & CarModel::AllLimitsInstance()
}
// static
VehicleModel::LimitsInitList const & CarModel::GetOptions() { return car_model::kDefaultOptions; }
VehicleModel::LimitsInitList const & CarModel::GetOptions()
{
return car_model::kDefaultOptions;
}
// static
VehicleModel::SurfaceInitList const & CarModel::GetSurfaces() { return car_model::kCarSurface; }
VehicleModel::SurfaceInitList const & CarModel::GetSurfaces()
{
return car_model::kCarSurface;
}
CarModelFactory::CarModelFactory(CountryParentNameGetterFn const & countryParentNameGetterFn)
: VehicleModelFactory(countryParentNameGetterFn)

View File

@@ -14,16 +14,18 @@ HighwayBasedFactors const kHighwayBasedFactors = {
// See XXX_KeepMotorway integration tests.
{HighwayType::HighwayMotorwayLink, InOutCityFactor(0.75)}, // 0.20 less
{HighwayType::HighwayTrunk, InOutCityFactor(0.90)},
{HighwayType::HighwayTrunkLink, InOutCityFactor(0.80)}, // 0.15 less
{HighwayType::HighwayTrunkLink, InOutCityFactor(0.80)}, // 0.15 less
// Tier 2:
{HighwayType::HighwayPrimary, InOutCityFactor(SpeedFactor{0.85 /* weight */, 0.80 /* eta */} /* in city */, 0.85 /* out city */)},
{HighwayType::HighwayPrimaryLink, InOutCityFactor(0.70 /* in city */, 0.75 /* out city */)}, // 0.10 less
{HighwayType::HighwayPrimary,
InOutCityFactor(SpeedFactor{0.85 /* weight */, 0.80 /* eta */} /* in city */, 0.85 /* out city */)},
{HighwayType::HighwayPrimaryLink, InOutCityFactor(0.70 /* in city */, 0.75 /* out city */)}, // 0.10 less
{HighwayType::HighwaySecondary, InOutCityFactor(0.80 /* in city */, 0.85 /* out city */)},
{HighwayType::HighwaySecondaryLink, InOutCityFactor(0.70 /* in city */, 0.75 /* out city */)}, // 0.10 less
{HighwayType::HighwaySecondaryLink, InOutCityFactor(0.70 /* in city */, 0.75 /* out city */)}, // 0.10 less
// Tier 3:
{HighwayType::HighwayTertiary, InOutCityFactor(0.70 /* in city */, 0.75 /* out city */)}, // 0.10 less than Secondary
{HighwayType::HighwayTertiary,
InOutCityFactor(0.70 /* in city */, 0.75 /* out city */)}, // 0.10 less than Secondary
{HighwayType::HighwayTertiaryLink, InOutCityFactor(0.60 /* in city */, 0.65 /* out city */)}, // 0.10 less
{HighwayType::HighwayUnclassified, InOutCityFactor(0.70 /* in city */, 0.75 /* out city */)},

View File

@@ -30,9 +30,10 @@ MaxspeedType SpeedInUnits::GetSpeedKmPH() const
// Maxspeed ----------------------------------------------------------------------------------------
Maxspeed::Maxspeed(Units units, MaxspeedType forward, MaxspeedType backward)
: m_units(units), m_forward(forward), m_backward(backward)
{
}
: m_units(units)
, m_forward(forward)
, m_backward(backward)
{}
bool Maxspeed::operator==(Maxspeed const & rhs) const
{
@@ -49,7 +50,8 @@ MaxspeedType Maxspeed::GetSpeedKmPH(bool forward) const
auto const speedInUnits = GetSpeedInUnits(forward);
switch (speedInUnits)
{
case kInvalidSpeed: return kInvalidSpeed; // That means IsValid() returns false.
case kInvalidSpeed:
return kInvalidSpeed; // That means IsValid() returns false.
// A feature is marked as a feature without any speed limits (maxspeed=="none").
// Should be less than CarModel::kMaxCarSpeedKMpH.
@@ -66,9 +68,9 @@ MaxspeedType Maxspeed::GetSpeedKmPH(bool forward) const
// FeatureMaxspeed ---------------------------------------------------------------------------------
FeatureMaxspeed::FeatureMaxspeed(uint32_t fid, measurement_utils::Units units, MaxspeedType forward,
MaxspeedType backward /* = kInvalidSpeed */) noexcept
: m_featureId(fid), m_maxspeed(units, forward, backward)
{
}
: m_featureId(fid)
, m_maxspeed(units, forward, backward)
{}
bool FeatureMaxspeed::operator==(FeatureMaxspeed const & rhs) const
{
@@ -302,7 +304,7 @@ SpeedInUnits MaxspeedConverter::ClosestValidMacro(SpeedInUnits const & speed) co
// static
MaxspeedConverter const & MaxspeedConverter::Instance()
{
static const MaxspeedConverter inst;
static MaxspeedConverter const inst;
return inst;
}
@@ -318,8 +320,7 @@ bool HaveSameUnits(SpeedInUnits const & lhs, SpeedInUnits const & rhs)
bool IsNumeric(MaxspeedType speed)
{
return (speed != kInvalidSpeed && speed != kNoneMaxSpeed &&
speed != kWalkMaxSpeed && speed != kCommonMaxSpeedValue);
return (speed != kInvalidSpeed && speed != kNoneMaxSpeed && speed != kWalkMaxSpeed && speed != kCommonMaxSpeedValue);
}
namespace
@@ -335,7 +336,7 @@ std::string PrintMaxspeedType(MaxspeedType s)
}
return std::to_string(int(s));
}
} // namespace
} // namespace
string DebugPrint(Maxspeed maxspeed)
{
@@ -349,8 +350,8 @@ string DebugPrint(Maxspeed maxspeed)
string DebugPrint(SpeedMacro maxspeed)
{
ostringstream oss;
oss << "SpeedMacro { " << static_cast<int>(maxspeed) << ", decoded: "
<< DebugPrint(GetMaxspeedConverter().MacroToSpeed(maxspeed)) << " }";
oss << "SpeedMacro { " << static_cast<int>(maxspeed)
<< ", decoded: " << DebugPrint(GetMaxspeedConverter().MacroToSpeed(maxspeed)) << " }";
return oss.str();
}

View File

@@ -18,8 +18,8 @@ enum class SpeedMacro : uint8_t
{
// Special values.
Undefined,
None, // No maxspeed restriction (E.g. a motorway in Germany).
Walk, // Driver should move as a walking person.
None, // No maxspeed restriction (E.g. a motorway in Germany).
Walk, // Driver should move as a walking person.
// Km per hour.
Speed1KmPH = 10,
@@ -257,18 +257,12 @@ public:
struct Less
{
bool operator() (FeatureMaxspeed const & l, FeatureMaxspeed const & r) const
bool operator()(FeatureMaxspeed const & l, FeatureMaxspeed const & r) const
{
return l.m_featureId < r.m_featureId;
}
bool operator() (uint32_t l, FeatureMaxspeed const & r) const
{
return l < r.m_featureId;
}
bool operator() (FeatureMaxspeed const & l, uint32_t r) const
{
return l.m_featureId < r;
}
bool operator()(uint32_t l, FeatureMaxspeed const & r) const { return l < r.m_featureId; }
bool operator()(FeatureMaxspeed const & l, uint32_t r) const { return l.m_featureId < r; }
};
bool IsValid() const { return m_maxspeed.IsValid(); }

View File

@@ -31,18 +31,12 @@ public:
m_idToFile.push_back(file);
m_fileToId[file] = id;
//LOG(LDEBUG, ("MWM:", file.GetName(), "=", id));
// LOG(LDEBUG, ("MWM:", file.GetName(), "=", id));
}
bool ContainsFile(platform::CountryFile const & file) const
{
return m_fileToId.find(file) != m_fileToId.cend();
}
bool ContainsFile(platform::CountryFile const & file) const { return m_fileToId.find(file) != m_fileToId.cend(); }
bool ContainsFileForMwm(NumMwmId mwmId) const
{
return mwmId < m_idToFile.size();
}
bool ContainsFileForMwm(NumMwmId mwmId) const { return mwmId < m_idToFile.size(); }
platform::CountryFile const & GetFile(NumMwmId mwmId) const
{

View File

@@ -2,16 +2,15 @@
#include "indexer/classificator.hpp"
namespace pedestrian_model
{
using namespace routing;
// See model specifics in different countries here:
// https://wiki.openstreetmap.org/wiki/OSM_tags_for_routing/Access-Restrictions
// Document contains proposals for some countries, but we assume that some kinds of roads are ready for pedestrian routing,
// but not listed in tables in the document. For example, steps are not listed, paths, roads and services features also
// can be treated as ready for pedestrian routing. These road types were added to lists below.
// Document contains proposals for some countries, but we assume that some kinds of roads are ready for pedestrian
// routing, but not listed in tables in the document. For example, steps are not listed, paths, roads and services
// features also can be treated as ready for pedestrian routing. These road types were added to lists below.
// See road types here:
// https://wiki.openstreetmap.org/wiki/Key:highway
@@ -85,8 +84,7 @@ VehicleModel::LimitsInitList const kDefaultOptions = {
{HighwayType::HighwayPedestrian, true},
{HighwayType::HighwayFootway, true},
{HighwayType::ManMadePier, true},
{HighwayType::RouteFerry, true}
};
{HighwayType::RouteFerry, true}};
// Same as defaults except bridleway and cycleway are allowed.
VehicleModel::LimitsInitList AllAllowed()
@@ -103,10 +101,8 @@ VehicleModel::LimitsInitList NoTrunk()
VehicleModel::LimitsInitList res;
res.reserve(kDefaultOptions.size() - 2);
for (auto const & e : kDefaultOptions)
{
if (e.m_type != HighwayType::HighwayTrunk && e.m_type != HighwayType::HighwayTrunkLink)
res.push_back(e);
}
return res;
}
@@ -133,31 +129,26 @@ HighwayBasedSpeeds IncreasePrimary()
}
VehicleModel::SurfaceInitList const kPedestrianSurface = {
// {{surfaceType}, {weightFactor, etaFactor}}
{{"psurface", "paved_good"}, {1.0, 1.0}},
{{"psurface", "paved_bad"}, {1.0, 1.0}},
{{"psurface", "unpaved_good"}, {1.0, 1.0}},
{{"psurface", "unpaved_bad"}, {0.8, 0.8}},
// no dedicated sidewalk, doesn't mean that foot is not allowed, just lower weight
{{"hwtag", "nosidewalk"}, {0.8, 0.8}},
// {{surfaceType}, {weightFactor, etaFactor}}
{{"psurface", "paved_good"}, {1.0, 1.0}},
{{"psurface", "paved_bad"}, {1.0, 1.0}},
{{"psurface", "unpaved_good"}, {1.0, 1.0}},
{{"psurface", "unpaved_bad"}, {0.8, 0.8}},
// no dedicated sidewalk, doesn't mean that foot is not allowed, just lower weight
{{"hwtag", "nosidewalk"}, {0.8, 0.8}},
};
} // namespace pedestrian_model
namespace routing
{
PedestrianModel::PedestrianModel() : PedestrianModel(pedestrian_model::kDefaultOptions)
{
}
PedestrianModel::PedestrianModel() : PedestrianModel(pedestrian_model::kDefaultOptions) {}
PedestrianModel::PedestrianModel(VehicleModel::LimitsInitList const & limits)
: PedestrianModel(limits, pedestrian_model::kDefaultSpeeds)
{
}
: PedestrianModel(limits, pedestrian_model::kDefaultSpeeds)
{}
PedestrianModel::PedestrianModel(VehicleModel::LimitsInitList const & limits,
HighwayBasedSpeeds const & speeds)
: VehicleModel(classif(), limits, pedestrian_model::kPedestrianSurface,
{speeds, pedestrian_model::kDefaultFactors})
PedestrianModel::PedestrianModel(VehicleModel::LimitsInitList const & limits, HighwayBasedSpeeds const & speeds)
: VehicleModel(classif(), limits, pedestrian_model::kPedestrianSurface, {speeds, pedestrian_model::kDefaultFactors})
{
using namespace pedestrian_model;
@@ -167,10 +158,10 @@ PedestrianModel::PedestrianModel(VehicleModel::LimitsInitList const & limits,
std::vector<std::string> hwtagYesFoot = {"hwtag", "yesfoot"};
auto const & cl = classif();
m_noType = cl.GetTypeByPath({ "hwtag", "nofoot" });
m_noType = cl.GetTypeByPath({"hwtag", "nofoot"});
m_yesType = cl.GetTypeByPath(hwtagYesFoot);
AddAdditionalRoadTypes(cl, {{ std::move(hwtagYesFoot), kDefaultSpeeds.Get(HighwayType::HighwayLivingStreet) }});
AddAdditionalRoadTypes(cl, {{std::move(hwtagYesFoot), kDefaultSpeeds.Get(HighwayType::HighwayLivingStreet)}});
// Update max pedestrian speed with possible ferry transfer. See EdgeEstimator::CalcHeuristic.
SpeedKMpH constexpr kMaxPedestrianSpeedKMpH(60.0);
@@ -183,7 +174,10 @@ SpeedKMpH PedestrianModel::GetSpeed(FeatureTypes const & types, SpeedParams cons
return GetTypeSpeedImpl(types, speedParams, false /* isCar */);
}
SpeedKMpH const & PedestrianModel::GetOffroadSpeed() const { return pedestrian_model::kSpeedOffroadKMpH; }
SpeedKMpH const & PedestrianModel::GetOffroadSpeed() const
{
return pedestrian_model::kSpeedOffroadKMpH;
}
// If one of feature types will be disabled for pedestrian, features of this type will be simplyfied
// in generator. Look FeatureBuilder1::IsRoad() for more details.
@@ -194,8 +188,7 @@ PedestrianModel const & PedestrianModel::AllLimitsInstance()
return instance;
}
PedestrianModelFactory::PedestrianModelFactory(
CountryParentNameGetterFn const & countryParentNameGetterFn)
PedestrianModelFactory::PedestrianModelFactory(CountryParentNameGetterFn const & countryParentNameGetterFn)
: VehicleModelFactory(countryParentNameGetterFn)
{
using namespace pedestrian_model;
@@ -233,4 +226,4 @@ PedestrianModelFactory::PedestrianModelFactory(
m_models["United Kingdom"] = make_shared<PedestrianModel>(AllAllowed());
m_models["United States of America"] = make_shared<PedestrianModel>(AllAllowed());
}
} // routing
} // namespace routing

View File

@@ -10,8 +10,7 @@ class PedestrianModel : public VehicleModel
public:
PedestrianModel();
explicit PedestrianModel(VehicleModel::LimitsInitList const & speedLimits);
PedestrianModel(VehicleModel::LimitsInitList const & limits,
HighwayBasedSpeeds const & speeds);
PedestrianModel(VehicleModel::LimitsInitList const & limits, HighwayBasedSpeeds const & speeds);
/// VehicleModelInterface overrides:
SpeedKMpH GetSpeed(FeatureTypes const & types, SpeedParams const & speedParams) const override;

View File

@@ -20,10 +20,7 @@ public:
return std::dynamic_pointer_cast<VehicleModel>(BicycleModelFactory().GetVehicleModelForCountry(country));
}
SpeedParams DefaultSpeedParams()
{
return {true /* forward */, true /* isCity */, Maxspeed()};
}
SpeedParams DefaultSpeedParams() { return {true /* forward */, true /* isCity */, Maxspeed()}; }
};
UNIT_CLASS_TEST(BicycleModelTest, Turkey)
@@ -39,4 +36,4 @@ UNIT_CLASS_TEST(BicycleModelTest, Turkey)
TEST_EQUAL(model->GetSpeed(holder, DefaultSpeedParams()), BicycleModel::DismountSpeed(), ());
}
} // namespace bicycle_model_test
} // namespace bicycle_model_test

View File

@@ -43,8 +43,8 @@ void TestVehicleModelDefault()
VehicleModelFactoryType vehicleModelFactory = VehicleModelFactoryType(GetRegionParent);
// Use static_pointer_cast here because VehicleModelInterface do not have EqualsForTests method
shared_ptr<VehicleModelType> defaultVehicleModelForCountry = static_pointer_cast<VehicleModelType>(
vehicleModelFactory.GetVehicleModelForCountry("Nonexistent Country Name"));
shared_ptr<VehicleModelType> defaultVehicleModelForCountry =
static_pointer_cast<VehicleModelType>(vehicleModelFactory.GetVehicleModelForCountry("Nonexistent Country Name"));
TEST(defaultVehicleModel->EqualsForTests(*defaultVehicleModelForCountry),
("Vehicle model for nonexistent counry is not equal to default."));
}
@@ -77,8 +77,7 @@ void ParentTest(string child, string parent)
shared_ptr<VehicleModelType> vehicleModelParent =
static_pointer_cast<VehicleModelType>(vehicleModelFactory.GetVehicleModelForCountry(parent));
TEST(vehicleModelChild->EqualsForTests(*vehicleModelParent),
("Can not expand car model for", child, "to", parent));
TEST(vehicleModelChild->EqualsForTests(*vehicleModelParent), ("Can not expand car model for", child, "to", parent));
}
// Test we have default vehicle models for nonexistent(unknown) country
@@ -112,7 +111,7 @@ UNIT_CLASS_TEST(VehicleModelForCountryTest, CarModel_DirectParent)
UNIT_CLASS_TEST(VehicleModelForCountryTest, BicycleModel_DirectParent)
{
// Road types for RF are equal with defaults (speeds are not compared).
// TestHaveNondefaultRestrictionForSelectedCountry<BicycleModel, BicycleModelFactory>("Russian Federation");
// TestHaveNondefaultRestrictionForSelectedCountry<BicycleModel, BicycleModelFactory>("Russian Federation");
ParentTest<BicycleModel, BicycleModelFactory>("Moscow", "Russian Federation");
}
@@ -121,8 +120,7 @@ UNIT_CLASS_TEST(VehicleModelForCountryTest, BicycleModel_DirectParent)
// Moscow equals pedestrian model for Russia and it's not default model.
UNIT_CLASS_TEST(VehicleModelForCountryTest, PedestrianModel_DirectParent)
{
TestHaveNondefaultRestrictionForSelectedCountry<PedestrianModel, PedestrianModelFactory>(
"Russian Federation");
TestHaveNondefaultRestrictionForSelectedCountry<PedestrianModel, PedestrianModelFactory>("Russian Federation");
ParentTest<PedestrianModel, PedestrianModelFactory>("Moscow", "Russian Federation");
}
@@ -138,8 +136,7 @@ UNIT_CLASS_TEST(VehicleModelForCountryTest, CarModel_InirectParent)
// San Francisco in GetRegionParent function: San Francisco -> California -> United States of America
UNIT_CLASS_TEST(VehicleModelForCountryTest, BicycleModel_IndirectParent)
{
TestHaveNondefaultRestrictionForSelectedCountry<BicycleModel, BicycleModelFactory>(
"United States of America");
TestHaveNondefaultRestrictionForSelectedCountry<BicycleModel, BicycleModelFactory>("United States of America");
ParentTest<BicycleModel, BicycleModelFactory>("San Francisco", "United States of America");
}
@@ -147,8 +144,7 @@ UNIT_CLASS_TEST(VehicleModelForCountryTest, BicycleModel_IndirectParent)
// San Francisco in GetRegionParent function: San Francisco -> California -> United States of America
UNIT_CLASS_TEST(VehicleModelForCountryTest, PedestrianModel_IndirectParent)
{
TestHaveNondefaultRestrictionForSelectedCountry<PedestrianModel, PedestrianModelFactory>(
"United States of America");
TestHaveNondefaultRestrictionForSelectedCountry<PedestrianModel, PedestrianModelFactory>("United States of America");
ParentTest<PedestrianModel, PedestrianModelFactory>("San Francisco", "United States of America");
}
} // namespace vehicle_model_for_country_test

View File

@@ -15,7 +15,6 @@
#include "base/math.hpp"
namespace vehicle_model_test
{
using namespace routing;
@@ -26,35 +25,27 @@ HighwayBasedSpeeds const kDefaultSpeeds = {
{HighwayType::HighwayPrimary, InOutCitySpeedKMpH(90.0 /* in city */, 120.0 /* out city */)},
{HighwayType::HighwaySecondary,
InOutCitySpeedKMpH(SpeedKMpH(80.0 /* weight */, 70.0 /* eta */) /* in and out city*/)},
{HighwayType::HighwayResidential,
InOutCitySpeedKMpH(SpeedKMpH(45.0 /* weight */, 55.0 /* eta */) /* in city */,
SpeedKMpH(50.0 /* weight */, 60.0 /* eta */) /* out city */)},
{HighwayType::HighwayService,
InOutCitySpeedKMpH(SpeedKMpH(47.0 /* weight */, 36.0 /* eta */) /* in city */,
SpeedKMpH(50.0 /* weight */, 40.0 /* eta */) /* out city */)}
};
{HighwayType::HighwayResidential, InOutCitySpeedKMpH(SpeedKMpH(45.0 /* weight */, 55.0 /* eta */) /* in city */,
SpeedKMpH(50.0 /* weight */, 60.0 /* eta */) /* out city */)},
{HighwayType::HighwayService, InOutCitySpeedKMpH(SpeedKMpH(47.0 /* weight */, 36.0 /* eta */) /* in city */,
SpeedKMpH(50.0 /* weight */, 40.0 /* eta */) /* out city */)}};
HighwayBasedFactors const kDefaultFactors = {
{HighwayType::HighwayTrunk, InOutCityFactor(1.0)},
{HighwayType::HighwayPrimary, InOutCityFactor(1.0)},
{HighwayType::HighwaySecondary, InOutCityFactor(1.0)},
{HighwayType::HighwayResidential, InOutCityFactor(0.5)}
};
HighwayBasedFactors const kDefaultFactors = {{HighwayType::HighwayTrunk, InOutCityFactor(1.0)},
{HighwayType::HighwayPrimary, InOutCityFactor(1.0)},
{HighwayType::HighwaySecondary, InOutCityFactor(1.0)},
{HighwayType::HighwayResidential, InOutCityFactor(0.5)}};
VehicleModel::LimitsInitList const kTestLimits = {
{HighwayType::HighwayTrunk, true},
{HighwayType::HighwayPrimary, true},
{HighwayType::HighwaySecondary, true},
{HighwayType::HighwayResidential, true},
{HighwayType::HighwayService, false}
};
VehicleModel::LimitsInitList const kTestLimits = {{HighwayType::HighwayTrunk, true},
{HighwayType::HighwayPrimary, true},
{HighwayType::HighwaySecondary, true},
{HighwayType::HighwayResidential, true},
{HighwayType::HighwayService, false}};
VehicleModel::SurfaceInitList const kCarSurface = {
{{"psurface", "paved_good"}, {0.8 /* weightFactor */, 0.9 /* etaFactor */}},
{{"psurface", "paved_bad"}, {0.4, 0.5}},
{{"psurface", "unpaved_good"}, {0.6, 0.8}},
{{"psurface", "unpaved_bad"}, {0.2, 0.2}}
};
{{"psurface", "unpaved_bad"}, {0.2, 0.2}}};
class VehicleModelTest
{
@@ -93,10 +84,7 @@ public:
class VehicleModelStub : public VehicleModel
{
public:
VehicleModelStub()
: VehicleModel(classif(), kTestLimits, kCarSurface, {kDefaultSpeeds, kDefaultFactors})
{
}
VehicleModelStub() : VehicleModel(classif(), kTestLimits, kCarSurface, {kDefaultSpeeds, kDefaultFactors}) {}
SpeedKMpH GetSpeed(feature::TypesHolder const & types, SpeedParams const & params) const override
{
@@ -150,7 +138,6 @@ void CheckPassThroughAllowed(initializer_list<uint32_t> const & types, bool expe
TEST_EQUAL(model.IsPassThroughAllowed(h), expectedValue, ());
}
UNIT_CLASS_TEST(VehicleModelStub, MaxSpeed)
{
TEST_EQUAL(GetMaxWeightSpeed(), 150.0, ());
@@ -207,9 +194,8 @@ UNIT_CLASS_TEST(VehicleModelTest, PassThroughAllowed)
UNIT_CLASS_TEST(VehicleModelTest, SpeedFactor)
{
CheckSpeed({secondary, pavedGood},
{SpeedKMpH(64.0 /* weight */, 63.0 /* eta */) /* in city */,
SpeedKMpH(64.0 /* weight */, 63.0 /* eta */) /* out of city */});
CheckSpeed({secondary, pavedGood}, {SpeedKMpH(64.0 /* weight */, 63.0 /* eta */) /* in city */,
SpeedKMpH(64.0 /* weight */, 63.0 /* eta */) /* out of city */});
CheckSpeed({secondary, pavedBad}, {SpeedKMpH(32.0, 35.0), SpeedKMpH(32.0, 35.0)});
CheckSpeed({secondary, unpavedGood}, {SpeedKMpH(48.0, 56.0), SpeedKMpH(48.0, 56.0)});
CheckSpeed({secondary, unpavedBad}, {SpeedKMpH(16.0, 14.0), SpeedKMpH(16.0, 14.0)});
@@ -227,28 +213,22 @@ UNIT_CLASS_TEST(VehicleModelTest, MaxspeedFactor)
Maxspeed const maxspeed90 = Maxspeed(units, 90, kInvalidSpeed);
// pavedBad == unpavedBad for the roads with explicitly defined speeds.
CheckSpeedWithParams({secondary, unpavedBad},
SpeedParams(true /* forward */, false /* in city */, maxspeed90),
CheckSpeedWithParams({secondary, unpavedBad}, SpeedParams(true /* forward */, false /* in city */, maxspeed90),
SpeedKMpH(36.0, 45.0));
CheckSpeedWithParams({secondary, pavedBad},
SpeedParams(true /* forward */, false /* in city */, maxspeed90),
CheckSpeedWithParams({secondary, pavedBad}, SpeedParams(true /* forward */, false /* in city */, maxspeed90),
SpeedKMpH(36.0, 45.0));
CheckSpeedWithParams({primary, pavedGood},
SpeedParams(true /* forward */, false /* in city */, maxspeed90),
CheckSpeedWithParams({primary, pavedGood}, SpeedParams(true /* forward */, false /* in city */, maxspeed90),
SpeedKMpH(72.0, 81.0));
Maxspeed const maxspeed9070 = Maxspeed(units, 90, 70);
CheckSpeedWithParams({primary, pavedGood},
SpeedParams(true /* forward */, false /* in city */, maxspeed9070),
CheckSpeedWithParams({primary, pavedGood}, SpeedParams(true /* forward */, false /* in city */, maxspeed9070),
SpeedKMpH(72.0, 81.0));
CheckSpeedWithParams({primary, pavedGood},
SpeedParams(false /* forward */, false /* in city */, maxspeed9070),
CheckSpeedWithParams({primary, pavedGood}, SpeedParams(false /* forward */, false /* in city */, maxspeed9070),
SpeedKMpH(56.0, 63.0));
Maxspeed const maxspeed60 = Maxspeed(units, 60, kInvalidSpeed);
CheckSpeedWithParams({residential, pavedGood},
SpeedParams(true /* forward */, false /* in city */, maxspeed60),
CheckSpeedWithParams({residential, pavedGood}, SpeedParams(true /* forward */, false /* in city */, maxspeed60),
SpeedKMpH(24.0, 27.0));
}
@@ -270,7 +250,7 @@ bool LessOrEqualSpeed(SpeedKMpH const & l, SpeedKMpH const & r)
}
#define TEST_LESS_OR_EQUAL_SPEED(l, r) TEST(LessOrEqualSpeed(l, r), (l, r))
} // namespace
} // namespace
UNIT_CLASS_TEST(VehicleModelTest, CarModel_TrackVsGravelTertiary)
{
@@ -283,7 +263,7 @@ UNIT_CLASS_TEST(VehicleModelTest, CarModel_TrackVsGravelTertiary)
feature::TypesHolder h2;
h2.Add(c.GetTypeByPath({"highway", "tertiary"}));
h2.Add(unpavedBad); // from OSM surface=gravel
h2.Add(unpavedBad); // from OSM surface=gravel
// https://www.openstreetmap.org/#map=19/45.43640/36.39689
// Obvious that gravel tertiary (moreover with maxspeed=60kmh) should be better than track.
@@ -354,23 +334,25 @@ UNIT_CLASS_TEST(VehicleModelTest, BicycleModel_Speeds)
auto const p = DefaultParams();
std::vector<std::vector<uint32_t>> const highways = {
{cycleway, pavedGood}, // TODO: should be higher than next, but is equal
{cycleway},
{cycleway, unpavedGood}, // TODO: should be lower than previous, but is equal
{footway, yesBicycle, pavedGood}, // TODO: should be higher than next, but is equal
{footway, yesBicycle},
{path, yesBicycle}, // TODO: unpaved by default, so should be lower than shared footways or cycleways, but is equal
{cycleway, pavedBad},
{footway, yesBicycle, pavedBad},
{footway}, // If allowed in the region.
{cycleway, unpavedBad},
{path, unpavedGood}, // Its controversial what is preferrable: a good path or a bad cycleway
{path, yesBicycle, unpavedBad},
/// @todo(pastk): "nobicycle" is ignored in speed calculation atm, the routing is just forbidden there.
/// But "nobicycle" should result in a dismount speed instead, see https://github.com/organicmaps/organicmaps/issues/9784
// {footway, c.GetTypeByPath({"hwtag", "nobicycle"})},
// {path, c.GetTypeByPath({"hwtag", "nobicycle"})},
{path, unpavedBad},
{cycleway, pavedGood}, // TODO: should be higher than next, but is equal
{cycleway},
{cycleway, unpavedGood}, // TODO: should be lower than previous, but is equal
{footway, yesBicycle, pavedGood}, // TODO: should be higher than next, but is equal
{footway, yesBicycle},
{path,
yesBicycle}, // TODO: unpaved by default, so should be lower than shared footways or cycleways, but is equal
{cycleway, pavedBad},
{footway, yesBicycle, pavedBad},
{footway}, // If allowed in the region.
{cycleway, unpavedBad},
{path, unpavedGood}, // Its controversial what is preferrable: a good path or a bad cycleway
{path, yesBicycle, unpavedBad},
/// @todo(pastk): "nobicycle" is ignored in speed calculation atm, the routing is just forbidden there.
/// But "nobicycle" should result in a dismount speed instead, see
/// https://github.com/organicmaps/organicmaps/issues/9784
// {footway, c.GetTypeByPath({"hwtag", "nobicycle"})},
// {path, c.GetTypeByPath({"hwtag", "nobicycle"})},
{path, unpavedBad},
};
feature::TypesHolder hprev;
@@ -415,18 +397,18 @@ UNIT_CLASS_TEST(VehicleModelTest, PedestrianModel_Speeds)
auto const p = DefaultParams();
std::vector<std::vector<uint32_t>> const highways = {
{footway, pavedGood}, // TODO: should be higher than next, but is equal
{footway},
{footway, pavedBad}, // TODO: should be lower than previous, but is equal
{footway, yesBicycle}, // TODO: should be lower than previous, but is equal
{path, yesFoot}, // TODO: should be higher than previous, but is equal
{path, unpavedGood}, // TODO: should be lower than previous, but is equal
{path, yesBicycle}, // TODO: should be lower than previous, but is equal
{cycleway},
{path, unpavedBad},
{cycleway, unpavedBad},
// {path, c.GetTypeByPath({"hwtag", "nofoot"})}, // TODO: should be forbidden, but has no effect ATM
// {cycleway, c.GetTypeByPath({"hwtag", "nofoot"})}, // TODO: should be forbidden, but has no effect ATM
{footway, pavedGood}, // TODO: should be higher than next, but is equal
{footway},
{footway, pavedBad}, // TODO: should be lower than previous, but is equal
{footway, yesBicycle}, // TODO: should be lower than previous, but is equal
{path, yesFoot}, // TODO: should be higher than previous, but is equal
{path, unpavedGood}, // TODO: should be lower than previous, but is equal
{path, yesBicycle}, // TODO: should be lower than previous, but is equal
{cycleway},
{path, unpavedBad},
{cycleway, unpavedBad},
// {path, c.GetTypeByPath({"hwtag", "nofoot"})}, // TODO: should be forbidden, but has no effect ATM
// {cycleway, c.GetTypeByPath({"hwtag", "nofoot"})}, // TODO: should be forbidden, but has no effect ATM
};
feature::TypesHolder hprev;
@@ -460,15 +442,12 @@ UNIT_TEST(VehicleModel_MultiplicationOperatorTest)
UNIT_TEST(VehicleModel_CarModelValidation)
{
HighwayType const carRoadTypes[] = {
HighwayType::HighwayLivingStreet, HighwayType::HighwayMotorway,
HighwayType::HighwayMotorwayLink, HighwayType::HighwayPrimary,
HighwayType::HighwayPrimaryLink, HighwayType::HighwayResidential,
HighwayType::HighwayRoad, HighwayType::HighwaySecondary,
HighwayType::HighwaySecondaryLink, HighwayType::HighwayService,
HighwayType::HighwayTertiary, HighwayType::HighwayTertiaryLink,
HighwayType::HighwayTrack, HighwayType::HighwayTrunk,
HighwayType::HighwayTrunkLink, HighwayType::HighwayUnclassified,
HighwayType::ManMadePier, HighwayType::RouteShuttleTrain,
HighwayType::HighwayLivingStreet, HighwayType::HighwayMotorway, HighwayType::HighwayMotorwayLink,
HighwayType::HighwayPrimary, HighwayType::HighwayPrimaryLink, HighwayType::HighwayResidential,
HighwayType::HighwayRoad, HighwayType::HighwaySecondary, HighwayType::HighwaySecondaryLink,
HighwayType::HighwayService, HighwayType::HighwayTertiary, HighwayType::HighwayTertiaryLink,
HighwayType::HighwayTrack, HighwayType::HighwayTrunk, HighwayType::HighwayTrunkLink,
HighwayType::HighwayUnclassified, HighwayType::ManMadePier, HighwayType::RouteShuttleTrain,
HighwayType::RouteFerry,
};
@@ -490,9 +469,7 @@ UNIT_TEST(VehicleModel_HighwayType_Values)
auto const & cl = classif();
auto const check = [&cl](HighwayType hwType, base::StringIL clType)
{
return static_cast<uint16_t>(hwType) == cl.GetIndexForType(cl.GetTypeByPath(clType));
};
{ return static_cast<uint16_t>(hwType) == cl.GetIndexForType(cl.GetTypeByPath(clType)); };
TEST(check(HighwayType::HighwayResidential, {"highway", "residential"}), ());
TEST(check(HighwayType::HighwayService, {"highway", "service"}), ());

View File

@@ -28,8 +28,8 @@ SpeedKMpH Max(SpeedKMpH const & lhs, InOutCitySpeedKMpH const & rhs)
VehicleModel::VehicleModel(Classificator const & classif, LimitsInitList const & featureTypeLimits,
SurfaceInitList const & featureTypeSurface, HighwayBasedInfo const & info)
: m_highwayBasedInfo(info)
, m_onewayType(ftypes::IsOneWayChecker::Instance().GetType())
: m_highwayBasedInfo(info)
, m_onewayType(ftypes::IsOneWayChecker::Instance().GetType())
{
m_roadTypes.Reserve(featureTypeLimits.size());
for (auto const & v : featureTypeLimits)
@@ -111,8 +111,7 @@ void VehicleModel::GetSurfaceFactor(uint32_t type, SpeedFactor & factor) const
ASSERT_GREATER(factor.m_eta, 0.0, ());
}
void VehicleModel::GetAdditionalRoadSpeed(uint32_t type, bool isCityRoad,
optional<SpeedKMpH> & speed) const
void VehicleModel::GetAdditionalRoadSpeed(uint32_t type, bool isCityRoad, optional<SpeedKMpH> & speed) const
{
auto const * s = m_addRoadTypes.Find(type);
if (s)
@@ -162,8 +161,8 @@ SpeedKMpH VehicleModel::GetTypeSpeedImpl(FeatureTypes const & types, SpeedParams
if (isCar)
{
// Override the global default speed with the MWM's saved default speed if they are not significantly differ (2x),
// to avoid anomaly peaks (especially for tracks).
// Override the global default speed with the MWM's saved default speed if they are not significantly differ
// (2x), to avoid anomaly peaks (especially for tracks).
/// @todo MWM saved speeds should be validated in generator.
if (params.m_defSpeedKmPH != kInvalidSpeed &&
fabs(speed.m_weight - params.m_defSpeedKmPH) / speed.m_weight < 1.0)
@@ -248,11 +247,9 @@ bool VehicleModel::IsRoadImpl(FeatureTypes const & types) const
return HasRoadType(types);
}
VehicleModelFactory::VehicleModelFactory(
CountryParentNameGetterFn const & countryParentNameGetterFn)
VehicleModelFactory::VehicleModelFactory(CountryParentNameGetterFn const & countryParentNameGetterFn)
: m_countryParentNameGetterFn(countryParentNameGetterFn)
{
}
{}
shared_ptr<VehicleModelInterface> VehicleModelFactory::GetVehicleModel() const
{
@@ -261,8 +258,7 @@ shared_ptr<VehicleModelInterface> VehicleModelFactory::GetVehicleModel() const
return itr->second;
}
shared_ptr<VehicleModelInterface> VehicleModelFactory::GetVehicleModelForCountry(
string const & country) const
shared_ptr<VehicleModelInterface> VehicleModelFactory::GetVehicleModelForCountry(string const & country) const
{
string parent = country;
while (!parent.empty())

View File

@@ -54,7 +54,7 @@ enum class HighwayType : uint16_t
HighwaySecondaryLink = 176,
RouteFerry = 259,
HighwayTertiaryLink = 272,
HighwayBusway = 857, // reserve type here, but this type is not used for any routing by default
HighwayBusway = 857, // reserve type here, but this type is not used for any routing by default
RouteShuttleTrain = 1054,
};
@@ -66,14 +66,17 @@ struct SpeedParams
{
/// @deprecated For unit tests compatibility.
SpeedParams(bool forward, bool inCity, Maxspeed const & maxspeed)
: m_maxspeed(maxspeed), m_defSpeedKmPH(kInvalidSpeed), m_inCity(inCity), m_forward(forward)
{
}
: m_maxspeed(maxspeed)
, m_defSpeedKmPH(kInvalidSpeed)
, m_inCity(inCity)
, m_forward(forward)
{}
SpeedParams(Maxspeed const & maxspeed, MaxspeedType defSpeedKmPH, bool inCity)
: m_maxspeed(maxspeed), m_defSpeedKmPH(defSpeedKmPH), m_inCity(inCity)
{
}
: m_maxspeed(maxspeed)
, m_defSpeedKmPH(defSpeedKmPH)
, m_inCity(inCity)
{}
// Maxspeed stored for feature, if any.
Maxspeed m_maxspeed;
@@ -92,22 +95,17 @@ struct SpeedKMpH
constexpr SpeedKMpH(double weight) noexcept : m_weight(weight), m_eta(weight) {}
constexpr SpeedKMpH(double weight, double eta) noexcept : m_weight(weight), m_eta(eta) {}
bool operator==(SpeedKMpH const & rhs) const
{
return m_weight == rhs.m_weight && m_eta == rhs.m_eta;
}
bool operator==(SpeedKMpH const & rhs) const { return m_weight == rhs.m_weight && m_eta == rhs.m_eta; }
bool operator!=(SpeedKMpH const & rhs) const { return !(*this == rhs); }
bool operator<(SpeedKMpH const & rhs) const
{
return m_weight < rhs.m_weight && m_eta < rhs.m_eta;
}
bool operator<(SpeedKMpH const & rhs) const { return m_weight < rhs.m_weight && m_eta < rhs.m_eta; }
bool IsValid() const { return m_weight > 0 && m_eta > 0; }
double m_weight = 0.0; // KMpH - speed in km/h adjusted for desirability
// cycling on very large road may be fast but speed used for route finding will be treated as much lower
double m_eta = 0.0; // KMpH - actual expected speed in km/h, used to display expected arrival time
double m_weight =
0.0; // KMpH - speed in km/h adjusted for desirability
// cycling on very large road may be fast but speed used for route finding will be treated as much lower
double m_eta = 0.0; // KMpH - actual expected speed in km/h, used to display expected arrival time
};
/// \brief Factors which modify weight and ETA speed on feature in case of bad pavement (reduce)
@@ -127,10 +125,7 @@ struct SpeedFactor
m_eta = std::max(f.m_eta, m_eta);
}
bool operator==(SpeedFactor const & rhs) const
{
return m_weight == rhs.m_weight && m_eta == rhs.m_eta;
}
bool operator==(SpeedFactor const & rhs) const { return m_weight == rhs.m_weight && m_eta == rhs.m_eta; }
bool operator!=(SpeedFactor const & rhs) const { return !(*this == rhs); }
double m_weight = 1.0;
@@ -150,14 +145,11 @@ inline SpeedKMpH operator*(SpeedKMpH const & speed, SpeedFactor const & factor)
struct InOutCitySpeedKMpH
{
constexpr InOutCitySpeedKMpH() = default;
constexpr explicit InOutCitySpeedKMpH(SpeedKMpH const & speed) noexcept
: m_inCity(speed), m_outCity(speed)
{
}
constexpr explicit InOutCitySpeedKMpH(SpeedKMpH const & speed) noexcept : m_inCity(speed), m_outCity(speed) {}
constexpr InOutCitySpeedKMpH(SpeedKMpH const & inCity, SpeedKMpH const & outCity) noexcept
: m_inCity(inCity), m_outCity(outCity)
{
}
: m_inCity(inCity)
, m_outCity(outCity)
{}
bool operator==(InOutCitySpeedKMpH const & rhs) const
{
@@ -173,19 +165,13 @@ struct InOutCitySpeedKMpH
struct InOutCityFactor
{
constexpr explicit InOutCityFactor(SpeedFactor const & factor) noexcept
: m_inCity(factor), m_outCity(factor)
{
}
constexpr explicit InOutCityFactor(SpeedFactor const & factor) noexcept : m_inCity(factor), m_outCity(factor) {}
constexpr InOutCityFactor(SpeedFactor const & inCity, SpeedFactor const & outCity) noexcept
: m_inCity(inCity), m_outCity(outCity)
{
}
: m_inCity(inCity)
, m_outCity(outCity)
{}
bool operator==(InOutCityFactor const & rhs) const
{
return m_inCity == rhs.m_inCity && m_outCity == rhs.m_outCity;
}
bool operator==(InOutCityFactor const & rhs) const { return m_inCity == rhs.m_inCity && m_outCity == rhs.m_outCity; }
SpeedFactor const & GetFactor(bool isCity) const { return isCity ? m_inCity : m_outCity; }
bool IsValid() const { return m_inCity.IsValid() && m_outCity.IsValid(); }
@@ -199,8 +185,7 @@ struct HighwayBasedInfo
HighwayBasedInfo(HighwayBasedSpeeds const & speeds, HighwayBasedFactors const & factors)
: m_speeds(speeds)
, m_factors(factors)
{
}
{}
HighwayBasedSpeeds m_speeds;
HighwayBasedFactors const & m_factors;
@@ -253,8 +238,7 @@ public:
virtual std::shared_ptr<VehicleModelInterface> GetVehicleModel() const = 0;
/// @return The most optimal vehicle model for specified country
virtual std::shared_ptr<VehicleModelInterface> GetVehicleModelForCountry(
std::string const & country) const = 0;
virtual std::shared_ptr<VehicleModelInterface> GetVehicleModelForCountry(std::string const & country) const = 0;
};
class VehicleModel : public VehicleModelInterface
@@ -263,7 +247,7 @@ public:
struct FeatureTypeLimits
{
HighwayType m_type;
bool m_isPassThroughAllowed; // pass through this road type is allowed
bool m_isPassThroughAllowed; // pass through this road type is allowed
};
struct FeatureTypeSurface
@@ -301,16 +285,16 @@ public:
/// @}
// Made public to have simple access from unit tests.
public:
/// @returns true if |m_highwayTypes| or |m_addRoadTypes| contains |type| and false otherwise.
bool IsRoadType(uint32_t type) const;
template <class TList> bool HasRoadType(TList const & types) const
template <class TList>
bool HasRoadType(TList const & types) const
{
for (uint32_t t : types)
{
if (IsRoadType(t))
return true;
}
return false;
}
@@ -337,8 +321,7 @@ protected:
private:
std::optional<HighwayType> GetHighwayType(uint32_t type) const;
void GetSurfaceFactor(uint32_t type, SpeedFactor & factor) const;
void GetAdditionalRoadSpeed(uint32_t type, bool isCityRoad,
std::optional<SpeedKMpH> & speed) const;
void GetAdditionalRoadSpeed(uint32_t type, bool isCityRoad, std::optional<SpeedKMpH> & speed) const;
// HW type -> speed and factor.
HighwayBasedInfo m_highwayBasedInfo;
@@ -366,8 +349,7 @@ public:
std::shared_ptr<VehicleModelInterface> GetVehicleModel() const override;
std::shared_ptr<VehicleModelInterface> GetVehicleModelForCountry(
std::string const & country) const override;
std::shared_ptr<VehicleModelInterface> GetVehicleModelForCountry(std::string const & country) const override;
protected:
explicit VehicleModelFactory(CountryParentNameGetterFn const & countryParentNameGetterFn);