import { tm_edge_kill } from "../tm_edge_kill.js";

/**
 * Removed edges from the mesh that are not connected to any faces
 * @param {TopoMesh} mesh
 * @returns {number} number of edges removed
 */
export function tm_edges_cleanup_empty(mesh) {
    /**
     *
     * @type {TopoEdge[]}
     */
    const garbage = [];

    // collect garbage
    for (const edge of mesh.getEdges()) {

        if (edge.faces.length === 0) {
            garbage.push(edge);
        }

    }

    // dispose

    const edge_count = garbage.length;
    for (let i = 0; i < edge_count; i++) {
        const edge = garbage[i];
        tm_edge_kill(mesh, edge);
    }

    return edge_count;
}