示例#1
0
void TestRouteGeometry(IndexGraphStarter & starter,
                       AStarAlgorithm<IndexGraphStarter>::Result expectedRouteResult,
                       vector<m2::PointD> const & expectedRouteGeom)
{
  vector<RoadPoint> route;
  auto const resultCode = CalculateRoute(starter, route);
  TEST_EQUAL(resultCode, expectedRouteResult, ());
  TEST_EQUAL(route.size(), expectedRouteGeom.size(), ());
  for (size_t i = 0; i < route.size(); ++i)
  {
    // When PR with applying restricions is merged IndexGraph::GetRoad() should be used here instead.
    RoadGeometry roadGeom = starter.GetGraph().GetGeometry().GetRoad(route[i].GetFeatureId());
    CHECK_LESS(route[i].GetPointId(), roadGeom.GetPointsCount(), ());
    TEST_EQUAL(expectedRouteGeom[i], roadGeom.GetPoint(route[i].GetPointId()), ());
  }
}
bool SingleMwmRouter::BuildRoute(MwmSet::MwmId const & mwmId, vector<Joint::Id> const & joints,
                                 RouterDelegate const & delegate, IndexGraphStarter & starter,
                                 Route & route) const
{
  vector<RoutePoint> routePoints;
  starter.RedressRoute(joints, routePoints);

  vector<Junction> junctions;
  junctions.reserve(routePoints.size());

  Geometry & geometry = starter.GetGraph().GetGeometry();
  // TODO: Use real altitudes for pedestrian and bicycle routing.
  for (RoutePoint const & routePoint : routePoints)
  {
    junctions.emplace_back(geometry.GetPoint(routePoint.GetRoadPoint()),
                           feature::kDefaultAltitudeMeters);
  }

  shared_ptr<traffic::TrafficInfo::Coloring> trafficColoring = m_trafficCache.GetTrafficInfo(mwmId);
  ReconstructRoute(m_directionsEngine.get(), m_roadGraph, trafficColoring, delegate, junctions,
                   route);

  // ReconstructRoute duplicates all points except start and finish.
  // Therefore one needs fix time indexes to fit reconstructed polyline.
  // TODO: rework ReconstructRoute and remove this stuff.
  if (routePoints.size() < 2 || route.GetPoly().GetSize() + 2 != routePoints.size() * 2)
  {
    LOG(LERROR, ("Can't fix route times: polyline size =", route.GetPoly().GetSize(),
                 "route points size =", routePoints.size()));
    return false;
  }

  Route::TTimes times;
  times.reserve(route.GetPoly().GetSize());
  times.emplace_back(0, routePoints.front().GetTime());

  for (size_t i = 1; i < routePoints.size() - 1; ++i)
  {
    times.emplace_back(i * 2 - 1, routePoints[i].GetTime());
    times.emplace_back(i * 2, routePoints[i].GetTime());
  }

  times.emplace_back(route.GetPoly().GetSize() - 1, routePoints.back().GetTime());
  route.SetSectionTimes(move(times));
  return true;
}