| 158 | } |
| 159 | |
| 160 | bool Router::Init(std::vector<WayPoint> const & points, double positiveOffsetM, double negativeOffsetM) |
| 161 | { |
| 162 | CHECK_GREATER_OR_EQUAL(points.size(), 2, ()); |
| 163 | |
| 164 | m_points = points; |
| 165 | m_positiveOffsetM = positiveOffsetM; |
| 166 | m_negativeOffsetM = negativeOffsetM; |
| 167 | |
| 168 | m_graph.ResetFakes(); |
| 169 | |
| 170 | m_pivots.clear(); |
| 171 | for (size_t i = 1; i + 1 < m_points.size(); ++i) |
| 172 | { |
| 173 | m_pivots.emplace_back(); |
| 174 | auto & ps = m_pivots.back(); |
| 175 | |
| 176 | std::vector<std::pair<routing::Edge, geometry::PointWithAltitude>> vicinity; |
| 177 | m_graph.FindClosestEdges( |
| 178 | mercator::RectByCenterXYAndSizeInMeters(m_points[i].m_point, routing::FeaturesRoadGraph::kClosestEdgesRadiusM), |
| 179 | kMaxRoadCandidates, vicinity); |
| 180 | for (auto const & v : vicinity) |
| 181 | { |
| 182 | auto const & e = v.first; |
| 183 | ps.push_back(e.GetStartJunction().GetPoint()); |
| 184 | ps.push_back(e.GetEndJunction().GetPoint()); |
| 185 | } |
| 186 | |
| 187 | if (ps.empty()) |
| 188 | return false; |
| 189 | } |
| 190 | |
| 191 | m_pivots.push_back({m_points.back().m_point}); |
| 192 | CHECK_EQUAL(m_pivots.size() + 1, m_points.size(), ()); |
| 193 | |
| 194 | { |
| 195 | m_sourceJunction = geometry::PointWithAltitude(m_points.front().m_point, 0 /* altitude */); |
| 196 | std::vector<std::pair<routing::Edge, geometry::PointWithAltitude>> sourceVicinity; |
| 197 | m_graph.FindClosestEdges(mercator::RectByCenterXYAndSizeInMeters(m_sourceJunction.GetPoint(), |
| 198 | routing::FeaturesRoadGraph::kClosestEdgesRadiusM), |
| 199 | kMaxRoadCandidates, sourceVicinity); |
| 200 | m_graph.AddFakeEdges(m_sourceJunction, sourceVicinity); |
| 201 | } |
| 202 | |
| 203 | { |
| 204 | m_targetJunction = geometry::PointWithAltitude(m_points.back().m_point, 0 /* altitude */); |
| 205 | std::vector<std::pair<routing::Edge, geometry::PointWithAltitude>> targetVicinity; |
| 206 | m_graph.FindClosestEdges(mercator::RectByCenterXYAndSizeInMeters(m_targetJunction.GetPoint(), |
| 207 | routing::FeaturesRoadGraph::kClosestEdgesRadiusM), |
| 208 | kMaxRoadCandidates, targetVicinity); |
| 209 | m_graph.AddFakeEdges(m_targetJunction, targetVicinity); |
| 210 | } |
| 211 | |
| 212 | return true; |
| 213 | } |
| 214 | |
| 215 | bool Router::FindPath(Path & path) |
| 216 | { |
no test coverage detected