diff options
author | Yuri Gorshenin <y@maps.me> | 2015-04-21 18:42:01 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:47:09 +0300 |
commit | 7c219d079023a18be28ab00c811e147e858a975c (patch) | |
tree | fee091904a63b1ac01c3907f4c1cacd7f969acae /routing/features_road_graph.cpp | |
parent | d3711f17ce2f52e1af102c4c7f22b1646b1c5b6d (diff) |
[pedestrian] Fixed turns tests.
Diffstat (limited to 'routing/features_road_graph.cpp')
-rw-r--r-- | routing/features_road_graph.cpp | 100 |
1 files changed, 25 insertions, 75 deletions
diff --git a/routing/features_road_graph.cpp b/routing/features_road_graph.cpp index a7b5992f46..f06969680d 100644 --- a/routing/features_road_graph.cpp +++ b/routing/features_road_graph.cpp @@ -17,9 +17,6 @@ namespace { uint32_t const FEATURE_CACHE_SIZE = 10; double const READ_CROSS_EPSILON = 1.0E-4; - -bool IsStart(RoadPos const & rp) { return rp.GetFeatureId() == RoadPos::kFakeStartFeatureId; } -bool IsFinal(RoadPos const & rp) { return rp.GetFeatureId() == RoadPos::kFakeFinalFeatureId; } } // namespace /// @todo Factor out vehicle model as a parameter for the features graph. @@ -37,20 +34,13 @@ uint32_t FeaturesRoadGraph::GetStreetReadScale() { return scales::GetUpperScale( class CrossFeaturesLoader { - FeaturesRoadGraph & m_graph; - m2::PointD m_point; - IRoadGraph::TurnsVectorT & m_turns; - size_t m_count; - public: - CrossFeaturesLoader(FeaturesRoadGraph & graph, m2::PointD const & pt, - IRoadGraph::TurnsVectorT & turns) - : m_graph(graph), m_point(pt), m_turns(turns), m_count(0) + CrossFeaturesLoader(FeaturesRoadGraph & graph, m2::PointD const & point, + IRoadGraph::CrossTurnsLoader & turnsLoader) + : m_graph(graph), m_point(point), m_turnsLoader(turnsLoader) { } - size_t GetCount() const { return m_count; } - void operator()(FeatureType & ft) { FeatureID const fID = ft.GetID(); @@ -72,36 +62,13 @@ public: IRoadGraph::RoadInfo const & ri = m_graph.GetCachedRoadInfo(fID.m_offset, ft, false); ASSERT_EQUAL(speed, ri.m_speedKMPH, ()); - size_t const count = ri.m_points.size(); - - PossibleTurn t; - t.m_speedKMPH = ri.m_speedKMPH; - t.m_startPoint = ri.m_points[0]; - t.m_endPoint = ri.m_points[count - 1]; - - for (size_t i = 0; i < count; ++i) - { - m2::PointD const & p = ri.m_points[i]; - - /// @todo Is this a correct way to compare? - if (!m2::AlmostEqual(m_point, p)) - continue; - - if (i > 0) - { - ++m_count; - t.m_pos = RoadPos(fID.m_offset, true, i - 1, p); - m_turns.push_back(t); - } - - if (i < count - 1) - { - ++m_count; - t.m_pos = RoadPos(fID.m_offset, false, i, p); - m_turns.push_back(t); - } - } + m_turnsLoader(fID.m_offset, ri); } + +private: + FeaturesRoadGraph & m_graph; + m2::PointD m_point; + IRoadGraph::CrossTurnsLoader & m_turnsLoader; }; void FeaturesRoadGraph::LoadFeature(uint32_t featureId, FeatureType & ft) @@ -114,36 +81,26 @@ void FeaturesRoadGraph::LoadFeature(uint32_t featureId, FeatureType & ft) ASSERT_GREATER(ft.GetPointsCount(), 1, (featureId)); } -void FeaturesRoadGraph::GetNearestTurns(RoadPos const & pos, vector<PossibleTurn> & turns) +IRoadGraph::RoadInfo FeaturesRoadGraph::GetRoadInfo(uint32_t featureId) { - if (IsStart(pos)) - { - turns.insert(turns.end(), m_startVicinityTurns.begin(), m_startVicinityTurns.end()); - return; - } - if (IsFinal(pos)) - { - turns.insert(turns.end(), m_finalVicinityTurns.begin(), m_finalVicinityTurns.end()); - return; - } - - uint32_t const featureId = pos.GetFeatureId(); FeatureType ft; - RoadInfo const ri = GetCachedRoadInfo(featureId, ft, true); - - if (ri.m_speedKMPH <= 0.0) - return; - - ASSERT_GREATER_OR_EQUAL(ri.m_points.size(), 2, - ("Incorrect road - only", ri.m_points.size(), "point(s).")); + return GetCachedRoadInfo(featureId, ft, true); +} - m2::PointD const point = ri.m_points[pos.GetSegStartPointId()]; +double FeaturesRoadGraph::GetSpeedKMPH(uint32_t featureId) +{ + FeatureType ft; + LoadFeature(featureId, ft); + return GetSpeedKMPHFromFt(ft); +} - // Find possible turns to startPoint from other features. - CrossFeaturesLoader crossLoader(*this, point, turns); - m_pIndex->ForEachInRect(crossLoader, - m2::RectD(point.x - READ_CROSS_EPSILON, point.y - READ_CROSS_EPSILON, - point.x + READ_CROSS_EPSILON, point.y + READ_CROSS_EPSILON), +void FeaturesRoadGraph::ForEachClosestToCrossFeature(m2::PointD const & cross, + CrossTurnsLoader & turnsLoader) +{ + CrossFeaturesLoader featuresLoader(*this, cross, turnsLoader); + m_pIndex->ForEachInRect(featuresLoader, + m2::RectD(cross.x - READ_CROSS_EPSILON, cross.y - READ_CROSS_EPSILON, + cross.x + READ_CROSS_EPSILON, cross.y + READ_CROSS_EPSILON), scales::GetUpperScale()); } @@ -157,13 +114,6 @@ double FeaturesRoadGraph::GetSpeedKMPHFromFt(FeatureType const & ft) const return m_vehicleModel->GetSpeed(ft); } -double FeaturesRoadGraph::GetSpeedKMPH(uint32_t featureId) -{ - FeatureType ft; - LoadFeature(featureId, ft); - return GetSpeedKMPHFromFt(ft); -} - IRoadGraph::RoadInfo const & FeaturesRoadGraph::GetCachedRoadInfo(uint32_t const ftId, FeatureType & ft, bool fullLoad) { |