From 4d82c421acd70a4d75f197063bd6addfd34b90df Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Fri, 6 May 2011 13:36:37 +0000 Subject: [PATCH] quadratic split error corrected [SVN r71763] --- .../rtree/linear/redistribute_elements.hpp | 30 +++++++--------- .../rtree/quadratic/redistribute_elements.hpp | 34 +++++++++++-------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/include/boost/geometry/extensions/index/rtree/linear/redistribute_elements.hpp b/include/boost/geometry/extensions/index/rtree/linear/redistribute_elements.hpp index bdaf2804f..a04b95521 100644 --- a/include/boost/geometry/extensions/index/rtree/linear/redistribute_elements.hpp +++ b/include/boost/geometry/extensions/index/rtree/linear/redistribute_elements.hpp @@ -231,17 +231,20 @@ struct redistribute_elements { element_type const& elem = elements_copy[i]; indexable_type const& indexable = rtree::element_indexable(elem, tr); - bool insert_into_group1 = false; // if there is small number of elements left and the number of elements in node is lesser than min_elems // just insert them to this node if ( elements1.size() + remaining <= min_elems ) { - insert_into_group1 = true; + elements1.push_back(elem); + geometry::expand(box1, indexable); + area1 = index::area(box1); } else if ( elements2.size() + remaining <= min_elems ) { - insert_into_group1 = false; + elements2.push_back(elem); + geometry::expand(box2, indexable); + area2 = index::area(box2); } // choose better node and insert element else @@ -262,26 +265,17 @@ struct redistribute_elements ( area_increase1 == area_increase2 && area1 < area2 ) || ( area1 == area2 && elements1.size() <= elements2.size() ) ) { - insert_into_group1 = true; + elements1.push_back(elem); + box1 = enlarged_box1; + area1 = enlarged_area1; } else { - insert_into_group1 = false; + elements2.push_back(elem); + box2 = enlarged_box2; + area2 = enlarged_area2; } } - - if ( insert_into_group1 ) - { - elements1.push_back(elem); - geometry::expand(box1, indexable); - area1 = index::area(box1); - } - else - { - elements2.push_back(elem); - geometry::expand(box2, indexable); - area2 = index::area(box2); - } assert(0 < remaining); --remaining; diff --git a/include/boost/geometry/extensions/index/rtree/quadratic/redistribute_elements.hpp b/include/boost/geometry/extensions/index/rtree/quadratic/redistribute_elements.hpp index 3f594e55f..75fcfec14 100644 --- a/include/boost/geometry/extensions/index/rtree/quadratic/redistribute_elements.hpp +++ b/include/boost/geometry/extensions/index/rtree/quadratic/redistribute_elements.hpp @@ -47,10 +47,11 @@ struct pick_seeds assert(2 <= elements_count); + area_type greatest_free_area = 0; seed1 = 0; seed2 = 1; - area_type greatest_free_area = 0; - for ( size_t i = 0 ; i < elements_count ; ++i ) + + for ( size_t i = 0 ; i < elements_count - 1 ; ++i ) { for ( size_t j = i + 1 ; j < elements_count ; ++j ) { @@ -164,9 +165,9 @@ struct redistribute_elements // find element with minimum groups areas increses differences area_type area_increase1 = 0; area_type area_increase2 = 0; - pick_next(elements_copy.rbegin(), elements_copy.rend(), - box1, box2, area1, area2, tr, - el_it, area_increase1, area_increase2); + el_it = pick_next(elements_copy.rbegin(), elements_copy.rend(), + box1, box2, area1, area2, tr, + area_increase1, area_increase2); if ( area_increase1 < area_increase2 || ( area_increase1 == area_increase2 && area1 < area2 ) || @@ -198,7 +199,7 @@ struct redistribute_elements } assert(!elements_copy.empty()); - elements_copy.erase(elements_copy.begin() + elements_copy.size() - 1); + elements_copy.erase(--el_it.base()); assert(0 < remaining); --remaining; @@ -208,21 +209,24 @@ struct redistribute_elements assert(min_elems <= elements2.size() && elements2.size() <= max_elems); } + // sprawdzic szukanie najmniejszego powiekszenia wezla dla grupy1 i grupy2 + template - static inline void pick_next(It first, It last, - Box const& box1, Box const& box2, - area_type const& area1, area_type const& area2, - Translator const& tr, - It out_it, area_type & out_area_increase1, area_type & out_area_increase2) + static inline It pick_next(It first, It last, + Box const& box1, Box const& box2, + area_type const& area1, area_type const& area2, + Translator const& tr, + area_type & out_area_increase1, area_type & out_area_increase2) { typedef typename boost::iterator_value::type element_type; typedef typename rtree::element_indexable_type::type indexable_type; area_type greatest_area_incrase_diff = 0; - out_it = first; + It out_it = first; out_area_increase1 = 0; out_area_increase2 = 0; - + + // find element with greatest difference between increased group's boxes areas for ( It el_it = first ; el_it != last ; ++el_it ) { indexable_type const& indexable = rtree::element_indexable(*el_it, tr); @@ -248,9 +252,9 @@ struct redistribute_elements out_area_increase1 = area_incrase1; out_area_increase2 = area_incrase2; } - - break; } + + return out_it; } };