diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_dcel_base.h b/Arrangement_on_surface_2/include/CGAL/Arr_dcel_base.h index 04a54c430fe..0b9f1d54cae 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_dcel_base.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_dcel_base.h @@ -516,10 +516,10 @@ public: typedef Inner_ccb Hole; private: - typedef Cast_function_object _Ccb_to_halfedge_cast; - // typedef Cast_function_object _Const_ccb_to_halfedge_cast; - typedef _Ccb_to_halfedge_cast _Const_ccb_to_halfedge_cast; + typedef Cast_function_object _Ccb_to_halfedge_cast; + // typedef Cast_function_object + // _Const_ccb_to_halfedge_cast; + typedef _Ccb_to_halfedge_cast _Const_ccb_to_halfedge_cast; public: @@ -667,6 +667,26 @@ public: /*! Erase an isloated vertex from the face. */ void erase_isolated_vertex(Isolated_vertex *iv) { this->iso_verts.erase(iv->iterator().current_iterator()); } + + /*! Move all isolated vertices from the face to another. */ + Isolated_vertex_iterator splice_isolated_vertices(Arr_face& other) + { + const bool was_empty = this->iso_verts.empty(); + typename Base::Isolated_vertices_container::iterator previous = + this->iso_verts.end(); + if (!was_empty) --previous; + this->iso_verts.splice(this->iso_verts.end(), other.iso_verts); + if (was_empty) previous = this->iso_verts.begin(); + else ++previous; + for (typename Base::Isolated_vertices_container::iterator it = previous; + it != this->iso_verts.end(); ++it) + { + Isolated_vertex* iv = static_cast(*it)->isolated_vertex(); + iv->set_iterator(it); + iv->set_face(this); + } + return previous; + } }; /*! \class diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_impl.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_impl.h index 475f2367bd6..6b3b4805241 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_impl.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_impl.h @@ -2095,6 +2095,33 @@ _move_isolated_vertex(DFace* from_face, DFace* to_face, DVertex* v) _notify_after_move_isolated_vertex(vh); } +//----------------------------------------------------------------------------- +// Move all isolated vertices from one face to another. +// +template +void Arrangement_on_surface_2:: +_move_all_isolated_vertices(DFace* from_face, DFace* to_face) +{ + // Comment EFEF 2015-09-28: The following loop and the loop at the end of this + // function should be replaced with a pair of notifiers, respectively, + // function_notify_before_move_all_isolated_vertices(); + // function_notify_after_move_all_isolated_vertices(); + DIso_vertex_iter iv_it = from_face->isolated_vertices_begin(); + while (iv_it != from_face->isolated_vertices_end()) { + DVertex* v = &(*iv_it++); + Vertex_handle vh(v); + _notify_before_move_isolated_vertex(Face_handle(from_face), + Face_handle(to_face), + vh); + } + iv_it = to_face->splice_isolated_vertices(*from_face); + while (iv_it != to_face->isolated_vertices_end()) { + DVertex* v = &(*iv_it++); + Vertex_handle vh(v); + _notify_after_move_isolated_vertex(vh); + } +} + //----------------------------------------------------------------------------- // Create a new vertex and associate it with the given point. // @@ -4874,16 +4901,7 @@ _remove_edge(DHalfedge* e, bool remove_source, bool remove_target) if (oc1->halfedge() == he1) oc1->set_halfedge(prev1); - // Move the isolated vertices inside f2 to f1. - DIso_vertex_iter iv_it = f2->isolated_vertices_begin(); - DIso_vertex_iter iv_to_move; - while (iv_it != f2->isolated_vertices_end()) { - // We increment the isolated vertices itrator before moving the vertex, - // because this operation invalidates the iterator. - iv_to_move = iv_it; - ++iv_it; - _move_isolated_vertex(f2, f1, &(*iv_to_move)); - } + _move_all_isolated_vertices(f2, f1); // move all iso vertices from f2 to f1 // If he1 or he2 are the incident halfedges to their target vertices, // we replace them by the appropriate predecessors. @@ -4987,17 +5005,7 @@ _remove_edge(DHalfedge* e, bool remove_source, bool remove_target) curr->set_inner_ccb(ic1); _move_all_inner_ccb(f2, f1); // move the inner CCBs from f2 to f1 - - // Move the isolated vertices inside f2 to f1. - DIso_vertex_iter iv_it = f2->isolated_vertices_begin(); - DIso_vertex_iter iv_to_move; - while (iv_it != f2->isolated_vertices_end()) { - // We increment the isolated vertices itrator before moving the vertex, - // because this operation invalidates the iterator. - iv_to_move = iv_it; - ++iv_it; - _move_isolated_vertex(f2, f1, &(*iv_to_move)); - } + _move_all_isolated_vertices(f2, f1); // move all iso vertices from f2 to f1 // Notice that f2 will be merged with f1, but its boundary will still be // a hole inside this face. In case he1 is a represantative of this hole, diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_on_surface_2.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_on_surface_2.h index ba7f166611e..8485b0d63ad 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_on_surface_2.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_on_surface_2.h @@ -1907,6 +1907,13 @@ protected: */ void _move_isolated_vertex(DFace* from_face, DFace* to_face, DVertex* v); + /*! + * Move all isolated vertices from one face to another. + * \param from_face The face currently containing the isolated vertices. + * \param to_face The face into which we should move the isolated vertices. + */ + void _move_all_isolated_vertices(DFace* from_face, DFace* to_face); + /*! * Create a new vertex and associate it with the given point. * \param p The point.