diff --git a/storage/country_info.cpp b/storage/country_info.cpp index b0b99d292c..db4f1588d1 100644 --- a/storage/country_info.cpp +++ b/storage/country_info.cpp @@ -108,9 +108,9 @@ namespace storage if (info.m_name.empty()) info.m_name = id; - if (id.find_first_of('_') != string::npos) + if (id.find('_') != string::npos) { - size_t const i = info.m_name.find_first_of('_'); + size_t const i = info.m_name.find('_'); ASSERT ( i != string::npos, () ); // replace '_' with ", " @@ -118,4 +118,19 @@ namespace storage info.m_name.insert(i+1, " "); } } + + m2::RectD CountryInfoGetter::CalcUSALimitRect() const + { + m2::RectD r; + for (size_t i = 0; i < m_countries.size(); ++i) + { + if ((m_countries[i].m_name.find("USA_") != string::npos) && + (m_countries[i].m_name != "USA_Alaska") && + (m_countries[i].m_name != "USA_Hawaii")) + { + r.Add(m_countries[i].m_rect); + } + } + return r; + } } diff --git a/storage/country_info.hpp b/storage/country_info.hpp index 1209fe85bf..06ac1ffd93 100644 --- a/storage/country_info.hpp +++ b/storage/country_info.hpp @@ -45,5 +45,7 @@ namespace storage void GetRegionInfo(m2::PointD const & pt, CountryInfo & info) const; void GetRegionInfo(string const & id, CountryInfo & info) const; + + m2::RectD CalcUSALimitRect() const; }; } diff --git a/storage/storage_tests/country_info_test.cpp b/storage/storage_tests/country_info_test.cpp index 5b9a91e07a..d41070ccfe 100644 --- a/storage/storage_tests/country_info_test.cpp +++ b/storage/storage_tests/country_info_test.cpp @@ -7,21 +7,31 @@ #include "../../platform/platform.hpp" +#include "../../base/logging.hpp" + using namespace storage; +namespace +{ + typedef storage::CountryInfoGetter CountryInfoT; + CountryInfoT * GetCountryInfo() + { + Platform & pl = GetPlatform(); + return new CountryInfoT(pl.GetReader(PACKED_POLYGONS_FILE), + pl.GetReader(COUNTRIES_FILE)); + } +} + UNIT_TEST(CountryInfo_GetByPoint_Smoke) { - Platform & pl = GetPlatform(); - - storage::CountryInfoGetter getter(pl.GetReader(PACKED_POLYGONS_FILE), - pl.GetReader(COUNTRIES_FILE)); + scoped_ptr getter(GetCountryInfo()); // Minsk CountryInfo info; - getter.GetRegionInfo(m2::PointD(MercatorBounds::LonToX(27.5618818), - MercatorBounds::LatToY(53.9022651)), - info); + getter->GetRegionInfo(m2::PointD(MercatorBounds::LonToX(27.5618818), + MercatorBounds::LatToY(53.9022651)), + info); TEST_EQUAL(info.m_name, "Belarus", ()); TEST_EQUAL(info.m_flag, "by", ()); @@ -51,3 +61,9 @@ UNIT_TEST(CountryInfo_ValidName_Smoke) TEST(IsEmptyName(id2info, "Russia_Far Eastern"), ()); TEST(IsEmptyName(id2info, "UK_Northern Ireland"), ()); } + +UNIT_TEST(CountryInfo_USARect) +{ + scoped_ptr getter(GetCountryInfo()); + LOG(LINFO, (getter->CalcUSALimitRect())); +}