/**
 *
 * @param {TopoVertex} v0
 * @param {TopoVertex} v1
 * @param {TopoVertex} target where to collapse v0 and v1 to
 * @param {Map<number,Quadric3>} quadratics
 * @returns {number}
 */
export function compute_edge_collapse_cost_quadratic(
    v0,
    v1,
    target,
    quadratics
) {
    const q0 = quadratics.get(v0.index);
    const q1 = quadratics.get(v1.index);

    const q_v0 = q0.evaluate(target.x, target.y, target.z);
    const q_v1 = q1.evaluate(target.x, target.y, target.z);

    /**
     * 'cost' shouldn't be negative but happens sometimes with small values.
     * @type {number}
     */
    const cost = Math.abs(q_v0 + q_v1);

    return cost;
}
