diff --git a/3party/kdtree++/kdtree.hpp b/3party/kdtree++/kdtree.hpp index 3b2d8badeb..ce3c11f451 100644 --- a/3party/kdtree++/kdtree.hpp +++ b/3party/kdtree++/kdtree.hpp @@ -402,11 +402,10 @@ namespace KDTree template bool for_any(ToDo toDo) const { - bool wasСalled = false; if (_M_get_root()) - _M_for_any(_M_get_root(), 0, toDo, wasСalled); + return _M_for_any(_M_get_root(), 0, toDo); - return wasСalled; + return false; } // compares via equality @@ -668,22 +667,18 @@ namespace KDTree } template - void _M_for_any(_Link_const_type N, size_type const L, ToDo toDo, bool & wasСalled) const + bool _M_for_any(_Link_const_type N, size_type const L, ToDo toDo) const { - if (wasСalled) - return; - if (toDo.DoIfIntersects(_S_value(N))) - { - wasСalled = true; - return; - } + return true; - if (_S_left(N) && toDo.ScanLeft(L, _S_value(N))) - _M_for_any(_S_left(N), L+1, toDo, wasСalled); + if (_S_left(N) && toDo.ScanLeft(L, _S_value(N)) && _M_for_any(_S_left(N), L+1, toDo)) + return true; - if (_S_right(N) && toDo.ScanRight(L, _S_value(N))) - _M_for_any(_S_right(N), L+1, toDo, wasСalled); + if (_S_right(N) && toDo.ScanRight(L, _S_value(N)) && _M_for_any(_S_right(N), L+1, toDo)) + return true; + + return false; } _Link_type diff --git a/geometry/geometry_tests/tree_test.cpp b/geometry/geometry_tests/tree_test.cpp index 5cf8ff06f8..437b9c4311 100644 --- a/geometry/geometry_tests/tree_test.cpp +++ b/geometry/geometry_tests/tree_test.cpp @@ -62,6 +62,21 @@ UNIT_TEST(Tree4D_Smoke) TEST_EQUAL(1, test.size(), ()); } +UNIT_TEST(Tree4D_ForAnyInRect) +{ + Tree theTree; + + R arr[] = {R(0, 0, 1, 1), R(0, 0, 5, 5), R(1, 1, 2, 2), + R(1, 1, 6.5, 6.5), R(2, 2, 3, 3), R(2, 2, 7, 7)}; + for (auto const & r : arr) + theTree.Add(r); + + TEST(theTree.ForAnyInRect(R(0, 0, 100, 100), [](R const & rect) { return rect.maxX() > 4; }), ()); + TEST(theTree.ForAnyInRect(R(0, 0, 100, 100), [](R const & rect) { return rect.maxX() > 5; }), ()); + TEST(theTree.ForAnyInRect(R(0, 0, 100, 100), [](R const & rect) { return rect.maxX() > 0; }), ()); + TEST(!theTree.ForAnyInRect(R(0, 0, 100, 100), [](R const & rect) { return rect.maxX() > 10; }), ()); +} + UNIT_TEST(Tree4D_ReplaceAllInRect) { Tree theTree;