Using in city properties for getting speed.

This commit is contained in:
Vladimir Byko-Ianko 2018-09-19 20:11:12 +03:00 committed by Vlad Mihaylenko
parent a9d9007eee
commit 5767b1f71c
3 changed files with 16 additions and 19 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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
{