| 455 | } |
| 456 | |
| 457 | Geocoder::ExtendedMwmInfos Geocoder::OrderCountries(bool inViewport, vector<MwmInfoPtr> const & infos) |
| 458 | { |
| 459 | set<storage::CountryId> mwmsWithCities; |
| 460 | set<storage::CountryId> mwmsWithStates; |
| 461 | if (!inViewport) |
| 462 | { |
| 463 | for (auto const & p : m_cities) |
| 464 | for (auto const & city : p.second) |
| 465 | mwmsWithCities.insert(m_infoGetter.GetRegionCountryId(city.m_rect.Center())); |
| 466 | for (auto const & p : m_regions[Region::TYPE_STATE]) |
| 467 | for (auto const & state : p.second) |
| 468 | mwmsWithStates.insert(m_infoGetter.GetRegionCountryId(state.m_center)); |
| 469 | } |
| 470 | |
| 471 | auto const hasMatchedCity = [&mwmsWithCities](auto const & i) |
| 472 | { return mwmsWithCities.count(i->GetCountryName()) != 0; }; |
| 473 | auto const hasMatchedState = [&mwmsWithStates](auto const & i) |
| 474 | { return mwmsWithStates.count(i->GetCountryName()) != 0; }; |
| 475 | |
| 476 | std::string locationMwm; |
| 477 | if (m_params.m_position) |
| 478 | locationMwm = m_infoGetter.GetRegionCountryId(*m_params.m_position); |
| 479 | |
| 480 | auto const viewportCenter = m_params.m_pivot.Center(); |
| 481 | std::string const viewportMwm = m_infoGetter.GetRegionCountryId(viewportCenter); |
| 482 | |
| 483 | ExtendedMwmInfos res; |
| 484 | res.m_infos.reserve(infos.size()); |
| 485 | for (auto const & info : infos) |
| 486 | { |
| 487 | ExtendedMwmInfos::ExtendedMwmInfo ei; |
| 488 | ei.m_info = info; |
| 489 | |
| 490 | auto const & rect = info->m_bordersRect; |
| 491 | ei.m_type.m_viewportIntersected = m_params.m_pivot.IsIntersect(rect); |
| 492 | ei.m_type.m_containsUserPosition = m_params.m_position && rect.IsPointInside(*m_params.m_position); |
| 493 | ei.m_type.m_containsMatchedCity = hasMatchedCity(info); |
| 494 | ei.m_type.m_containsMatchedState = hasMatchedState(info); |
| 495 | |
| 496 | // Order MWMs like: |
| 497 | // - World |
| 498 | // - containing viewport center |
| 499 | // - containing user's position (except viewport search mode) |
| 500 | // - less by viewport center or rect similarity |
| 501 | |
| 502 | if (info->GetType() == MwmInfo::WORLD) |
| 503 | ei.m_score = -6; |
| 504 | else if (info->GetCountryName() == viewportMwm) |
| 505 | ei.m_score = -4; |
| 506 | else if (!inViewport && ei.m_type.m_containsUserPosition) |
| 507 | { |
| 508 | ei.m_score = 0; |
| 509 | if (info->GetCountryName() == locationMwm) |
| 510 | ei.m_score = -2; |
| 511 | } |
| 512 | else |
| 513 | ei.m_score = GetDistanceMeters(viewportCenter, rect); |
| 514 |
nothing calls this directly
no test coverage detected