diff options
author | Добрый Ээх <bukharaev@gmail.com> | 2016-11-15 13:25:38 +0300 |
---|---|---|
committer | Добрый Ээх <bukharaev@gmail.com> | 2016-11-24 17:53:04 +0300 |
commit | 950801a350eca43b5202e4c436726cde52f1a5ed (patch) | |
tree | a6d53186354328651780783eb5ff9ff451f7d955 /routing/geometry.cpp | |
parent | be1213029222d42a7a230f6c165f668a1d0ffd8b (diff) |
Pull request #4672 review fixes
Diffstat (limited to 'routing/geometry.cpp')
-rw-r--r-- | routing/geometry.cpp | 117 |
1 files changed, 36 insertions, 81 deletions
diff --git a/routing/geometry.cpp b/routing/geometry.cpp index c7431f44bd..38c3359b0b 100644 --- a/routing/geometry.cpp +++ b/routing/geometry.cpp @@ -4,119 +4,74 @@ #include "base/assert.hpp" -namespace -{ using namespace routing; -double constexpr kMPH2MPS = 1000.0 / (60 * 60); - -inline double TimeBetweenSec(m2::PointD const & from, m2::PointD const & to, double speedMPS) +namespace { - ASSERT_GREATER(speedMPS, 0.0, ()); - - double const distanceM = MercatorBounds::DistanceOnEarth(from, to); - return distanceM / speedMPS; -} - -class GeometryImpl final : public Geometry +class GeometryLoaderImpl final : public GeometryLoader { public: - GeometryImpl(Index const & index, MwmSet::MwmId const & mwmId, - shared_ptr<IVehicleModel> vehicleModel); + GeometryLoaderImpl(Index const & index, MwmSet::MwmId const & mwmId, + shared_ptr<IVehicleModel> vehicleModel); - // Geometry overrides: - bool IsRoad(uint32_t featureId) const override; - bool IsOneWay(uint32_t featureId) const override; - m2::PointD const & GetPoint(FSegId fseg) const override; - double CalcEdgesWeight(uint32_t featureId, uint32_t pointStart, - uint32_t pointFinish) const override; - double CalcHeuristic(FSegId from, FSegId to) const override; + // GeometryLoader overrides: + virtual void Load(uint32_t featureId, RoadGeometry & road) const override; private: - FeatureType const & GetFeature(uint32_t featureId) const; - FeatureType const & LoadFeature(uint32_t featureId) const; - Index const & m_index; MwmSet::MwmId const m_mwmId; shared_ptr<IVehicleModel> m_vehicleModel; - double const m_maxSpeedMPS; - mutable map<uint32_t, FeatureType> m_features; + Index::FeaturesLoaderGuard m_guard; }; -GeometryImpl::GeometryImpl(Index const & index, MwmSet::MwmId const & mwmId, - shared_ptr<IVehicleModel> vehicleModel) - : m_index(index) - , m_mwmId(mwmId) - , m_vehicleModel(vehicleModel) - , m_maxSpeedMPS(vehicleModel->GetMaxSpeed() * kMPH2MPS) -{ -} - -bool GeometryImpl::IsRoad(uint32_t featureId) const -{ - return m_vehicleModel->IsRoad(GetFeature(featureId)); -} - -bool GeometryImpl::IsOneWay(uint32_t featureId) const -{ - return m_vehicleModel->IsOneWay(GetFeature(featureId)); -} - -m2::PointD const & GeometryImpl::GetPoint(FSegId fseg) const +GeometryLoaderImpl::GeometryLoaderImpl(Index const & index, MwmSet::MwmId const & mwmId, + shared_ptr<IVehicleModel> vehicleModel) + : m_index(index), m_mwmId(mwmId), m_vehicleModel(vehicleModel), m_guard(m_index, m_mwmId) { - return GetFeature(fseg.GetFeatureId()).GetPoint(fseg.GetSegId()); + ASSERT(m_vehicleModel, ()); } -double GeometryImpl::CalcEdgesWeight(uint32_t featureId, uint32_t pointFrom, uint32_t pointTo) const +void GeometryLoaderImpl::Load(uint32_t featureId, RoadGeometry & road) const { - uint32_t const start = min(pointFrom, pointTo); - uint32_t const finish = max(pointFrom, pointTo); - FeatureType const & feature = GetFeature(featureId); - - ASSERT_LESS(finish, feature.GetPointsCount(), ()); - - double result = 0.0; - double const speedMPS = m_vehicleModel->GetSpeed(feature) * kMPH2MPS; - for (uint32_t i = start; i < finish; ++i) + FeatureType feature; + bool const isFound = m_guard.GetFeatureByIndex(featureId, feature); + if (!isFound) { - result += TimeBetweenSec(feature.GetPoint(i), feature.GetPoint(i + 1), speedMPS); + LOG(LERROR, ("Feature", featureId, "not found")); + return; } - return result; + feature.ParseGeometry(FeatureType::BEST_GEOMETRY); + road.Load(*m_vehicleModel, feature); } +} // namespace -double GeometryImpl::CalcHeuristic(FSegId from, FSegId to) const +namespace routing +{ +RoadGeometry::RoadGeometry(bool oneWay, double speed, Points const & points) + : m_isRoad(true), m_isOneWay(oneWay), m_speed(speed), m_points(points) { - return TimeBetweenSec(GetPoint(from), GetPoint(to), m_maxSpeedMPS); } -FeatureType const & GeometryImpl::GetFeature(uint32_t featureId) const +void RoadGeometry::Load(IVehicleModel const & vehicleModel, FeatureType const & feature) { - auto it = m_features.find(featureId); - if (it != m_features.end()) - return it->second; + m_isRoad = vehicleModel.IsRoad(feature); + m_isOneWay = vehicleModel.IsOneWay(feature); + m_speed = vehicleModel.GetSpeed(feature); - return LoadFeature(featureId); + m_points.reserve(feature.GetPointsCount()); + for (size_t i = 0; i < feature.GetPointsCount(); ++i) + m_points.emplace_back(feature.GetPoint(i)); } -FeatureType const & GeometryImpl::LoadFeature(uint32_t featureId) const +Geometry::Geometry(unique_ptr<GeometryLoader> loader) : m_loader(move(loader)) { - Index::FeaturesLoaderGuard guard(m_index, m_mwmId); - FeatureType & feature = m_features[featureId]; - bool const isFound = guard.GetFeatureByIndex(featureId, feature); - ASSERT(isFound, ("Feature", featureId, "not found")); - if (isFound) - feature.ParseGeometry(FeatureType::BEST_GEOMETRY); - - return feature; + ASSERT(m_loader, ()); } -} // namespace -namespace routing -{ -unique_ptr<Geometry> CreateGeometry(Index const & index, MwmSet::MwmId const & mwmId, - shared_ptr<IVehicleModel> vehicleModel) +unique_ptr<GeometryLoader> CreateGeometryLoader(Index const & index, MwmSet::MwmId const & mwmId, + shared_ptr<IVehicleModel> vehicleModel) { - return make_unique<GeometryImpl>(index, mwmId, vehicleModel); + return make_unique<GeometryLoaderImpl>(index, mwmId, vehicleModel); } } // namespace routing |