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

/**
 *
 * @param {number[]} result
 * @param {number} result_offset
 * @param {TetrahedralMesh} mesh
 * @param {number} vertex_index
 * @returns {number}
 */
export function tetrahedral_mesh_find_tets_attached_to_vertex(
    result, result_offset,
    mesh, vertex_index
) {

    assert.isNonNegativeInteger(vertex_index, "vertex_index");

    let offset = result_offset;

    mesh.forEach((tet) => {

        for (let i = 0; i < 4; i++) {
            const vert = mesh.getVertexIndex(tet, i);

            if (vert === vertex_index) {
                result[offset++] = tet;
                break;
            }
        }

    });

    return offset - result_offset;
}