@@ -504,26 +504,54 @@ is_valid(bool verbose, int level) const
504504 bool result = true ;
505505
506506 // verify correctness of triangulation at all levels
507- for (int i=0 ; i<maxlevel; ++i)
507+ for (int i=0 ; i<maxlevel; ++i){
508508 result = result && hierarchy[i]->is_valid (verbose, level);
509-
510- // verify that lower level has no down pointers
509+ if (verbose && (! result)){
510+ std::cerr << " triangulation at level " << i << " invalid" << std::endl;
511+ }
512+ }
513+ // verify that lowest level has no down pointers
511514 for ( Finite_vertices_iterator it = hierarchy[0 ]->finite_vertices_begin (),
512- end = hierarchy[0 ]->finite_vertices_end (); it != end; ++it)
515+ end = hierarchy[0 ]->finite_vertices_end (); it != end; ++it){
513516 result = result && (it->down () == Vertex_handle ());
517+ if (verbose && (! result)){
518+ std::cerr << " lowest level has a down pointer" << std::endl;
519+ }
520+ }
514521
515- // verify that other levels has down pointer and reciprocal link is fine
522+ // verify that other levels have down pointer and reciprocal link is fine
516523 for (int j=1 ; j<maxlevel; ++j)
517524 for ( Finite_vertices_iterator it = hierarchy[j]->finite_vertices_begin (),
518525 end = hierarchy[j]->finite_vertices_end (); it != end; ++it)
519- result = result && &*(it) == &*(it->down ()->up ());
526+ {
527+ result = result && (it->down () != Vertex_handle ());
528+ if (verbose && (! result)){
529+ std::cerr << " missing down pointer" << std::endl;
530+ }
531+ if (it->down () == Vertex_handle ()){
532+ return false ;
533+ }
534+ result = result && Vertex_handle (it) == Vertex_handle (it->down ()->up ());
535+ if (verbose && (! result)){
536+ std::cerr << " wrong reciprocal link with down()" << std::endl;
537+ }
538+ result = result && Vertex_handle (it)->point () == Vertex_handle (it->down ())->point ();
539+ if (verbose && (! result)){
540+ std::cerr << " inconsistent vertex positions" << std::endl;
541+ }
542+ }
520543
521- // verify that other levels has down pointer and reciprocal link is fine
544+ // verify that all levels have up pointer and reciprocal link is fine
522545 for (int k=0 ; k<maxlevel-1 ; ++k)
523546 for ( Finite_vertices_iterator it = hierarchy[k]->finite_vertices_begin (),
524547 end = hierarchy[k]->finite_vertices_end (); it != end; ++it)
548+ {
525549 result = result && ( it->up () == Vertex_handle () ||
526- &*it == &*(it->up ())->down () );
550+ Vertex_handle (it) == Vertex_handle (it->up ())->down () );
551+ if (verbose && (! result)){
552+ std::cerr << " wrong reciprocal link with up()" << std::endl;
553+ }
554+ }
527555
528556 return result;
529557}
@@ -718,14 +746,13 @@ move_if_no_collision(Vertex_handle v, const Point & p)
718746{
719747 CGAL_precondition (!this ->is_infinite (v));
720748 if (v->point () == p) return v;
721- Vertex_handle ans;
722- for (int l = 0 ; l < maxlevel; ++l) {
749+ Vertex_handle ans = hierarchy[0 ]->move_if_no_collision (v, p);
750+ if (ans != v) return ans; // ans is an existing vertex at p and v was not changed
751+ for (int l = 1 ; l < maxlevel; ++l) {
723752 Vertex_handle u = v->up ();
724- if (l) hierarchy[l]->move_if_no_collision (v, p);
725- else ans = hierarchy[l]->move_if_no_collision (v, p);
726- if (ans != v) return ans;
727753 if (u == Vertex_handle ())
728754 break ;
755+ hierarchy[l]->move_if_no_collision (u, p);
729756 v = u;
730757 }
731758 return ans;
0 commit comments