| 77 | // An implementation for CountriesFilesAffiliation class. |
| 78 | template <typename T> |
| 79 | std::vector<std::string> GetAffiliations(T const & t, borders::CountryPolygonsCollection const & countryPolygonsTree, |
| 80 | bool haveBordersForWholeWorld) |
| 81 | { |
| 82 | std::vector<std::string> countries; |
| 83 | std::vector<std::reference_wrapper<borders::CountryPolygons const>> countriesContainer; |
| 84 | countryPolygonsTree.ForEachCountryInRect( |
| 85 | GetLimitRect(t), [&](auto const & countryPolygons) { countriesContainer.emplace_back(countryPolygons); }); |
| 86 | |
| 87 | // todo(m.andrianov): We need to explore this optimization better. There is a hypothesis: some |
| 88 | // elements belong to a rectangle, but do not belong to the exact boundary. |
| 89 | if (haveBordersForWholeWorld && countriesContainer.size() == 1) |
| 90 | { |
| 91 | borders::CountryPolygons const & countryPolygons = countriesContainer.front(); |
| 92 | countries.emplace_back(countryPolygons.GetName()); |
| 93 | return countries; |
| 94 | } |
| 95 | |
| 96 | for (borders::CountryPolygons const & countryPolygons : countriesContainer) |
| 97 | { |
| 98 | auto const need = ForAnyPoint(t, [&](auto const & point) { return countryPolygons.Contains(point); }); |
| 99 | |
| 100 | if (need) |
| 101 | countries.emplace_back(countryPolygons.GetName()); |
| 102 | } |
| 103 | |
| 104 | return countries; |
| 105 | } |
| 106 | |
| 107 | // An implementation for CountriesFilesIndexAffiliation class. |
| 108 | using IndexSharedPtr = std::shared_ptr<CountriesFilesIndexAffiliation::Tree>; |
no test coverage detected