diff options
author | vng <viktor.govako@gmail.com> | 2010-12-29 02:28:10 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:08:51 +0300 |
commit | e82bdfd361c80bcee7997681b5bce7b100b82ab7 (patch) | |
tree | 240c364f25130f613193664a9181d857bb4fe51c /geometry | |
parent | 01e8135397f30bf9107228bd4006c8e0ec10d76b (diff) |
Filter texts by rect.
Diffstat (limited to 'geometry')
-rw-r--r-- | geometry/geometry_tests/tree_test.cpp | 11 | ||||
-rw-r--r-- | geometry/tree4d.hpp | 14 |
2 files changed, 13 insertions, 12 deletions
diff --git a/geometry/geometry_tests/tree_test.cpp b/geometry/geometry_tests/tree_test.cpp index 69a67cf3e0..bcc0721419 100644 --- a/geometry/geometry_tests/tree_test.cpp +++ b/geometry/geometry_tests/tree_test.cpp @@ -6,12 +6,7 @@ namespace { - struct simple_traits - { - static m2::RectD GetLimitRect(m2::RectD const & r) { return r; } - }; - - typedef m4::Tree<m2::RectD, simple_traits> tree_t; + typedef m4::Tree<m2::RectD> tree_t; bool compare_true(m2::RectD const &, m2::RectD const &) { return true; } } @@ -27,14 +22,14 @@ UNIT_TEST(Tree4D_Smoke) }; for (size_t i = 0; i < ARRAY_SIZE(arr); ++i) - theTree.ReplaceIf(arr[i], &compare_true); + theTree.ReplaceIf(arr[i], arr[i], &compare_true); vector<m2::RectD> test; theTree.ForEach(MakeBackInsertFunctor(test)); TEST_EQUAL(3, test.size(), ()); m2::RectD const replaceR(0.5, 0.5, 2.5, 2.5); - theTree.ReplaceIf(replaceR, &compare_true); + theTree.ReplaceIf(replaceR, replaceR, &compare_true); test.clear(); theTree.ForEach(MakeBackInsertFunctor(test)); diff --git a/geometry/tree4d.hpp b/geometry/tree4d.hpp index 7e22ed290f..c03dbb61ad 100644 --- a/geometry/tree4d.hpp +++ b/geometry/tree4d.hpp @@ -10,7 +10,7 @@ namespace m4 { - template <class T, class TTraits> + template <class T> class Tree { struct value_t @@ -44,10 +44,8 @@ namespace m4 public: template <class TCompare> - void ReplaceIf(T const & obj, TCompare comp) + void ReplaceIf(T const & obj, m2::RectD const & rect, TCompare comp) { - m2::RectD const rect = TTraits::GetLimitRect(obj); - region_t rgn; for (size_t i = 0; i < 4; ++i) { @@ -96,11 +94,19 @@ namespace m4 m_tree.insert(value_t(obj, rect)); } + template <class TCompare> + void ReplaceIf(T const & obj, TCompare comp) + { + ReplaceIf(obj, obj.GetLimitRect(), comp); + } + template <class ToDo> void ForEach(ToDo toDo) const { for (tree_t::const_iterator i = m_tree.begin(); i != m_tree.end(); ++i) toDo((*i).m_val); } + + void Clear() { m_tree.clear(); } }; } |