// Copyright (c) 2014 GeometryFactory (France). All rights reserved. // // This file is part of CGAL (www.cgal.org) // // $URL: https://github.com/CGAL/cgal/blob/v5.1/BGL/include/CGAL/boost/graph/internal/helpers.h $ // $Id: helpers.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Andread Fabri #ifndef CGAL_BOOST_GRAPH_INTERNAL_HELPERS_H #define CGAL_BOOST_GRAPH_INTERNAL_HELPERS_H #include #include #include namespace CGAL { // breaks a dependency loop between // and template class Halfedge_around_target_iterator; namespace internal { template void set_border(typename boost::graph_traits::halfedge_descriptor const& h , Graph& g) { set_face(h, boost::graph_traits::null_face(), g); } template typename boost::graph_traits::halfedge_descriptor copy(typename boost::graph_traits::halfedge_descriptor const& h , Graph& g) { typename boost::graph_traits::edge_descriptor e = add_edge(g); typename boost::graph_traits::halfedge_descriptor res = halfedge(e,g); typename boost::graph_traits::halfedge_descriptor ropp = opposite(res, g); typename boost::graph_traits::halfedge_descriptor hopp = opposite(h, g); set_target(res, target(h, g), g); set_target(hopp, target(hopp, g), g); set_face(res, face(h, g), g); set_face(ropp, face(hopp, g), g); // note that we cannot call set_next as it then would call set_prev on the original return res; } template void set_vertex_halfedge(typename boost::graph_traits::halfedge_descriptor const& h , Graph& g) { set_halfedge(target(h, g), h, g); } template void close_tip(typename boost::graph_traits::halfedge_descriptor const& h , Graph& g) { // makes `opposite(h,g)' the successor of h. set_next( h, opposite(h, g), g); } template void close_tip(typename boost::graph_traits::halfedge_descriptor const& h , typename boost::graph_traits::vertex_descriptor const& v , Graph& g) { // makes `h->opposite()' the successor of h and sets the incident // vertex of h to v. set_next(h, opposite(h, g), g); set_target(h, v, g); set_halfedge(v, h, g); } template void insert_tip(typename boost::graph_traits::halfedge_descriptor const& h , typename boost::graph_traits::halfedge_descriptor const& h2 , Graph& g) { set_next(h, next(h2,g), g); set_next(h2, opposite(h, g), g); set_target(h, target(h2, g), g); } template void remove_tip(typename boost::graph_traits::halfedge_descriptor const& h , Graph& g) { set_next(h, next(opposite(next(h, g), g), g), g); } template void set_face_in_face_loop(typename boost::graph_traits::halfedge_descriptor h, typename boost::graph_traits::face_descriptor f, Graph& g) { typename boost::graph_traits::halfedge_descriptor end = h; do { set_face(h, f, g); h = next(h, g); } while ( h != end); } template void insert_halfedge(typename boost::graph_traits::halfedge_descriptor const& h , typename boost::graph_traits::halfedge_descriptor const& f , Graph& g) { set_next(h, next(f, g), g); set_next(f, h, g); set_face(h, face(f, g), g); } template std::size_t exact_num_vertices(const Graph& g) { typename boost::graph_traits::vertex_iterator beg, end; boost::tie(beg,end) = vertices(g); return std::distance(beg,end); } template std::size_t exact_num_halfedges(const Graph& g) { typename boost::graph_traits::halfedge_iterator beg, end; boost::tie(beg,end) = halfedges(g); return std::distance(beg,end); } template std::size_t exact_num_edges(const Graph& g) { typename boost::graph_traits::edge_iterator beg, end; boost::tie(beg,end) = edges(g); return std::distance(beg,end); } template std::size_t exact_num_faces(const Graph& g) { typename boost::graph_traits::face_iterator beg, end; boost::tie(beg,end) = faces(g); return std::distance(beg,end); } template bool is_isolated(typename boost::graph_traits::vertex_descriptor v, Graph& g) { return halfedge(v, g) == boost::graph_traits::null_halfedge(); } template void adjust_incoming_halfedge(typename boost::graph_traits::vertex_descriptor v, Graph& g) { typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; halfedge_descriptor h = halfedge(v, g); halfedge_descriptor hh = h; if (h != boost::graph_traits::null_halfedge()) { if (target(h, g) != v) { // wrong target, flip h = opposite(h, g); hh = h; set_halfedge(v, h, g); } do { if(face(h, g)==boost::graph_traits::null_face()) { set_halfedge(v, h, g); return; } h = opposite(next(h, g), g); } while (h != hh); } } } // internal } // CGAL #endif // CGAL_BOOST_GRAPH_INTERNAL_HELPERS_H