Merge pull request #7686 from sloriot/SS-fix_size_after_remove

Correct size() in case some points were removed
This commit is contained in:
Laurent Rineau 2023-09-06 11:52:40 +02:00
commit e8d819742b
1 changed files with 10 additions and 10 deletions

View File

@ -137,7 +137,7 @@ private:
mutable CGAL_MUTEX building_mutex;//mutex used to protect const calls inducing build() mutable CGAL_MUTEX building_mutex;//mutex used to protect const calls inducing build()
#endif #endif
bool built_; bool built_;
bool removed_; std::size_t removed_=0;
// protected copy constructor // protected copy constructor
Kd_tree(const Tree& tree) Kd_tree(const Tree& tree)
@ -278,13 +278,13 @@ private:
public: public:
Kd_tree(Splitter s = Splitter(),const SearchTraits traits=SearchTraits()) Kd_tree(Splitter s = Splitter(),const SearchTraits traits=SearchTraits())
: traits_(traits),split(s), built_(false), removed_(false) : traits_(traits),split(s), built_(false)
{} {}
template <class InputIterator> template <class InputIterator>
Kd_tree(InputIterator first, InputIterator beyond, Kd_tree(InputIterator first, InputIterator beyond,
Splitter s = Splitter(),const SearchTraits traits=SearchTraits()) Splitter s = Splitter(),const SearchTraits traits=SearchTraits())
: traits_(traits), split(s), pts(first, beyond), built_(false), removed_(false) : traits_(traits), split(s), pts(first, beyond), built_(false)
{ } { }
bool empty() const { bool empty() const {
@ -324,7 +324,7 @@ public:
// must call invalidate_build() first. // must call invalidate_build() first.
CGAL_assertion(!is_built()); CGAL_assertion(!is_built());
CGAL_assertion(!pts.empty()); CGAL_assertion(!pts.empty());
CGAL_assertion(!removed_); CGAL_assertion(removed_==0);
const Point_d& p = *pts.begin(); const Point_d& p = *pts.begin();
typename SearchTraits::Construct_cartesian_const_iterator_d ccci=traits_.construct_cartesian_const_iterator_d_object(); typename SearchTraits::Construct_cartesian_const_iterator_d ccci=traits_.construct_cartesian_const_iterator_d_object();
dim_ = static_cast<int>(std::distance(ccci(p), ccci(p,0))); dim_ = static_cast<int>(std::distance(ccci(p), ccci(p,0)));
@ -432,14 +432,14 @@ public:
void invalidate_build() void invalidate_build()
{ {
if(removed_){ if(removed_!=0){
// Walk the tree to collect the remaining points. // Walk the tree to collect the remaining points.
// Writing directly to pts would likely work, but better be safe. // Writing directly to pts would likely work, but better be safe.
std::vector<Point_d> ptstmp; std::vector<Point_d> ptstmp;
//ptstmp.resize(root()->num_items()); //ptstmp.resize(root()->num_items());
root()->tree_items(std::back_inserter(ptstmp)); root()->tree_items(std::back_inserter(ptstmp));
pts.swap(ptstmp); pts.swap(ptstmp);
removed_=false; removed_=0;
CGAL_assertion(is_built()); // the rest of the cleanup must happen CGAL_assertion(is_built()); // the rest of the cleanup must happen
} }
if(is_built()){ if(is_built()){
@ -455,7 +455,7 @@ public:
{ {
invalidate_build(); invalidate_build();
pts.clear(); pts.clear();
removed_ = false; removed_ = 0;
} }
void void
@ -512,8 +512,8 @@ public:
CGAL_assertion(success); CGAL_assertion(success);
// Do not set the flag is the tree has been cleared. // Do not set the flag is the tree has been cleared.
if(is_built()) if(is_built() && success)
removed_ |= success; ++removed_;
} }
private: private:
template<class Equal> template<class Equal>
@ -684,7 +684,7 @@ public:
size_type size_type
size() const size() const
{ {
return pts.size(); return pts.size()-removed_;
} }
// Print statistics of the tree. // Print statistics of the tree.