/**
 * Removes vertices from the mesh not attached to any edges
 * @param {TopoMesh} mesh
 * @returns {number} number of vertices removed
 */
export function tm_vertices_cleanup_empty(mesh) {

    // collect garbage
    const vertices = mesh.vertices;
    let vertex_count = vertices.length;

    // remember for later
    const initial_vertex_count = vertex_count;

    for (let i = 0; i < vertex_count; i++) {
        const v = vertices[i];

        if (v.edges.length === 0) {
            // not connected
            vertices.splice(i, 1);

            // update iterator
            i--;
            vertex_count--;
        }

    }

    const removed_vertex_count = initial_vertex_count - vertex_count;

    return removed_vertex_count;
}