/*
 *  Copyright (c) 2000-2022 Inria
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice,
 *  this list of conditions and the following disclaimer in the documentation
 *  and/or other materials provided with the distribution.
 *  * Neither the name of the ALICE Project-Team nor the names of its
 *  contributors may be used to endorse or promote products derived from this
 *  software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 *
 *  Contact: Bruno Levy
 *
 *     https://www.inria.fr/fr/bruno-levy
 *
 *     Inria,
 *     Domaine de Voluceau,
 *     78150 Le Chesnay - Rocquencourt
 *     FRANCE
 *
 */

#ifndef GEOGRAM_MESH_LOCAL_OPERATIONS
#define GEOGRAM_MESH_LOCAL_OPERATIONS

#include <geogram/basic/common.h>
#include <geogram/basic/numeric.h>

/**
 * \file geogram/mesh/mesh_local_operations.h
 * \brief Functions to modify a mesh locally
 */

namespace GEO {

    class Mesh;

    /**
     * \brief Glues two edges on the border of a surface mesh.
     * \param[in] M a reference to the mesh
     * \param[in] f1 , c1 the first edge, as a corner seen from a facet
     * \param[in] f2 , c2 the second edge, as a corner seen from a facet
     * \pre Both edges are on the border
     */
    void GEOGRAM_API glue_edges(
        Mesh& M,
        index_t f1, index_t c1,
        index_t f2, index_t c2
    );

    /**
     * \brief Unglues an edge from its opposite edge.
     * \param[in,out] M a reference to the surface mesh
     * \param[in] f1 , c1 the edge, as a corner seen from a facet
     * \pre The edge (f,c) is not on the border
     */
    void GEOGRAM_API unglue_edges(Mesh& M, index_t f1, index_t c1);

    /**
     * \brief Flips an edge in a triangle mesh
     * \param[in,out] M a reference to the surface triangle mesh
     * \param[in] t a facet
     * \param[in] e in [0,1,2] the local edge index in facet \p t,
     *  using Geogram convention for edges (edge 0 starts from vertex 0).
     * \pre surface mesh \M is triangulated
     * \return true if the edge could be flip, false otherwise (if edge was on
     *  border)
     */
    bool GEOGRAM_API flip_edge(Mesh& M, index_t t, index_t e);
}

#endif
