| 486 | } |
| 487 | |
| 488 | void TestRouteGeometry(IndexGraphStarter & starter, AlgorithmForWorldGraph::Result expectedRouteResult, |
| 489 | vector<m2::PointD> const & expectedRouteGeom) |
| 490 | { |
| 491 | vector<Segment> routeSegs; |
| 492 | double timeSec = 0.0; |
| 493 | auto const resultCode = CalculateRoute(starter, routeSegs, timeSec); |
| 494 | |
| 495 | TEST_EQUAL(resultCode, expectedRouteResult, ()); |
| 496 | |
| 497 | if (AlgorithmForWorldGraph::Result::NoPath == expectedRouteResult && expectedRouteGeom.empty()) |
| 498 | { |
| 499 | // The route goes through a restriction. So there's no choice for building route |
| 500 | // except for going through restriction. So no path. |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | if (resultCode != AlgorithmForWorldGraph::Result::OK) |
| 505 | return; |
| 506 | |
| 507 | CHECK(!routeSegs.empty(), ()); |
| 508 | vector<m2::PointD> geom; |
| 509 | |
| 510 | auto const pushPoint = [&geom](ms::LatLon const & ll) |
| 511 | { |
| 512 | auto const point = mercator::FromLatLon(ll); |
| 513 | if (geom.empty() || geom.back() != point) |
| 514 | geom.push_back(point); |
| 515 | }; |
| 516 | |
| 517 | for (auto const & routeSeg : routeSegs) |
| 518 | { |
| 519 | auto const & ll = starter.GetPoint(routeSeg, false /* front */); |
| 520 | // Note. In case of A* router all internal points of route are duplicated. |
| 521 | // So it's necessary to exclude the duplicates. |
| 522 | pushPoint(ll); |
| 523 | } |
| 524 | |
| 525 | pushPoint(starter.GetPoint(routeSegs.back(), false /* front */)); |
| 526 | TEST_EQUAL(geom.size(), expectedRouteGeom.size(), ("geom:", geom, "expectedRouteGeom:", expectedRouteGeom)); |
| 527 | for (size_t i = 0; i < geom.size(); ++i) |
| 528 | { |
| 529 | static double constexpr kEps = 1e-8; |
| 530 | if (!AlmostEqualAbs(geom[i], expectedRouteGeom[i], kEps)) |
| 531 | { |
| 532 | for (size_t j = 0; j < geom.size(); ++j) |
| 533 | LOG(LINFO, (j, "=>", geom[j], "vs", expectedRouteGeom[j])); |
| 534 | |
| 535 | TEST(false, ("Point with number:", i, "doesn't equal to expected.")); |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | void TestRestrictions(vector<m2::PointD> const & expectedRouteGeom, AlgorithmForWorldGraph::Result expectedRouteResult, |
| 541 | FakeEnding const & start, FakeEnding const & finish, RestrictionVec && restrictions, |
no test coverage detected