diff --git a/geometry/tree4d.hpp b/geometry/tree4d.hpp index f0a61bb6d0..90dec33c09 100644 --- a/geometry/tree4d.hpp +++ b/geometry/tree4d.hpp @@ -220,14 +220,20 @@ namespace m4 } template - void ForEach(ToDo toDo) const + void ForEach(ToDo && toDo) const { for (ValueT const & v : m_tree) toDo(v.m_val); } + template + void ForEachEx(ToDo && toDo) const + { + for (ValueT const & v : m_tree) + toDo(v.GetRect(), v.m_val); + } template - bool FindNode(ToDo const & toDo) const + bool FindNode(ToDo && toDo) const { for (ValueT const & v : m_tree) if (toDo(v.m_val)) @@ -237,17 +243,15 @@ namespace m4 } template - void ForEachWithRect(ToDo toDo) const - { - for (ValueT const & v : m_tree) - toDo(v.GetRect(), v.m_val); - } - - template - void ForEachInRect(m2::RectD const & rect, ToDo toDo) const + void ForEachInRect(m2::RectD const & rect, ToDo && toDo) const { m_tree.for_each(GetFunctor(rect, [&toDo] (ValueT const & v) { toDo(v.m_val); })); } + template + void ForEachInRectEx(m2::RectD const & rect, ToDo && toDo) const + { + m_tree.for_each(GetFunctor(rect, [&toDo] (ValueT const & v) { toDo(v.GetRect(), v.m_val); })); + } bool IsEmpty() const { return m_tree.empty(); } diff --git a/search/locality_finder.cpp b/search/locality_finder.cpp index 4588498181..0831ca6c46 100644 --- a/search/locality_finder.cpp +++ b/search/locality_finder.cpp @@ -53,8 +53,8 @@ public: if (!ft.GetName(0, name)) return; - LocalityItem item(rect, population, id, name); - m_cache.m_tree.Add(item, item.GetLimitRect()); + LocalityItem item(population, id, name); + m_cache.m_tree.Add(item, rect); m_cache.m_loaded.insert(id); } @@ -73,9 +73,9 @@ public: { } - void operator() (LocalityItem const & item) + void operator() (m2::RectD const & rect, LocalityItem const & item) { - double const d = MercatorBounds::DistanceOnEarth(item.m_rect.Center(), m_point); + double const d = MercatorBounds::DistanceOnEarth(rect.Center(), m_point); double const value = ftypes::GetPopulationByRadius(d) / static_cast(item.m_population); if (value < m_bestValue) { @@ -91,11 +91,19 @@ private: }; -LocalityItem::LocalityItem(m2::RectD const & rect, uint32_t population, ID id, string const & name) - : m_rect(rect), m_name(name), m_population(population), m_id(id) +LocalityItem::LocalityItem(uint32_t population, ID id, string const & name) + : m_name(name), m_population(population), m_id(id) { } +string DebugPrint(LocalityItem const & item) +{ + stringstream ss; + ss << "Name = " << item.m_name << "Population = " << item.m_population << "ID = " << item.m_id; + return ss.str(); +} + + LocalityFinder::LocalityFinder(Index const * pIndex) : m_pIndex(pIndex), m_lang(0) { @@ -137,13 +145,11 @@ void LocalityFinder::RecreateCache(Cache & cache, m2::RectD rect) const ScaleIndex index(pMwm->m_cont.GetReader(INDEX_FILE_TAG), pMwm->m_factory); FeaturesVector loader(pMwm->m_cont, header, pMwm->m_table); - + DoLoader doLoader(*this, loader, cache); cache.m_rect = rect; + for (size_t i = 0; i < interval.size(); ++i) - { - DoLoader doLoader(*this, loader, cache); index.ForEachInIntervalAndScale(doLoader, interval[i].first, interval[i].second, scale); - } } } } @@ -226,7 +232,7 @@ void LocalityFinder::Cache::GetLocality(m2::PointD const & pt, string & name) co return; ++m_usage; - m_tree.ForEachInRect(m2::RectD(pt, pt), DoSelectLocality(name, pt)); + m_tree.ForEachInRectEx(m2::RectD(pt, pt), DoSelectLocality(name, pt)); } } diff --git a/search/locality_finder.hpp b/search/locality_finder.hpp index 89f59e7abc..b898818a28 100644 --- a/search/locality_finder.hpp +++ b/search/locality_finder.hpp @@ -16,16 +16,15 @@ namespace search struct LocalityItem { - m2::RectD m_rect; string m_name; uint32_t m_population; typedef uint32_t ID; ID m_id; - LocalityItem(m2::RectD const & rect, uint32_t population, ID id, string const & name); + LocalityItem(uint32_t population, ID id, string const & name); - m2::RectD const & GetLimitRect() const { return m_rect; } + friend string DebugPrint(LocalityItem const & item); }; class LocalityFinder