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

/**
 *
 * @param {TopoMesh} mesh
 * @param {BinaryHeap<EdgeCollapseCandidate>} heap
 * @param {Map<TopoEdge, EdgeCollapseCandidate>} edge_map
 * @param {Map<number, Quadric3>} vertex_quadratics
 * @param {Set<number>} restricted_vertices
 */
export function build_edge_collapse_candidates(
    mesh,
    heap,
    edge_map,
    vertex_quadratics,
    restricted_vertices
) {
    assert.equal(mesh.isTopoMesh, true, 'mesh.isTopoMesh !== true');

    const edges = mesh.getEdges();
    for (let candidate_edge of edges) {

        // update edge length, as it's used in the cost metric
        candidate_edge.computeSquaredLength();

        const e = new EdgeCollapseCandidate();
        e.edge = candidate_edge;

        const is_valid = e.update(vertex_quadratics, restricted_vertices);

        if (is_valid) {
            heap.push(e);

            edge_map.set(candidate_edge, e);
        }

    }
}
