diff options
author | vng <viktor.govako@gmail.com> | 2012-08-23 11:25:26 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:42:27 +0300 |
commit | f8679434b8f1e2668d447dc8eb11ca0c7c168fb6 (patch) | |
tree | 1a05cf0ae12e3190dc306d93c7fcdf5dbdf59045 /storage | |
parent | 7cf9981c61381384b9668c592e5072382f70f24d (diff) |
[search] Process country or state in address search.
Diffstat (limited to 'storage')
-rw-r--r-- | storage/country_info.cpp | 22 | ||||
-rw-r--r-- | storage/country_info.hpp | 19 |
2 files changed, 40 insertions, 1 deletions
diff --git a/storage/country_info.cpp b/storage/country_info.cpp index b7343ff706..2ca2f6eae2 100644 --- a/storage/country_info.cpp +++ b/storage/country_info.cpp @@ -205,4 +205,26 @@ namespace storage ForEachCountry(prefix, bind(&AddRect, ref(r), _1)); return r; } + + void CountryInfoGetter::GetMatchedRegions(string const & enName, IDSet & regions) const + { + for (size_t i = 0; i < m_countries.size(); ++i) + { + /// @todo Check for any matching now. Do it smarter in future. + string s = m_countries[i].m_name; + strings::AsciiToLower(s); + if (s.find(enName) != string::npos) + regions.push_back(i); + } + } + + bool CountryInfoGetter::IsBelongToRegion(m2::PointD const & pt, IDSet const & regions) const + { + GetByPoint doCheck(*this, pt); + for (size_t i = 0; i < regions.size(); ++i) + if (m_countries[regions[i]].m_rect.IsPointInside(pt) && !doCheck(regions[i])) + return true; + + return false; + } } diff --git a/storage/country_info.hpp b/storage/country_info.hpp index 5dcd95d970..3cbedcabb0 100644 --- a/storage/country_info.hpp +++ b/storage/country_info.hpp @@ -38,7 +38,12 @@ namespace storage size_t m_res; GetByPoint(CountryInfoGetter const & info, m2::PointD const & pt) - : m_info(info), m_pt(pt), m_res(-1) {} + : m_info(info), m_pt(pt), m_res(-1) + { + } + + /// @param[in] id Index in m_countries. + /// @return false If point is in country. bool operator() (size_t id); }; @@ -59,5 +64,17 @@ namespace storage void CalcUSALimitRect(m2::RectD rects[3]) const; m2::RectD CalcLimitRect(string const & prefix) const; + + /// @name Used for checking that objects (by point) are belong to regions. + //@{ + /// ID of region (index in m_countries array). + typedef size_t IDType; + typedef vector<IDType> IDSet; + + /// @param[in] enName English name to match (should be in lower case). + /// Search is case-insensitive. + void GetMatchedRegions(string const & enName, IDSet & regions) const; + bool IsBelongToRegion(m2::PointD const & pt, IDSet const & regions) const; + //@} }; } |