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

/**
 * Debug method that validates cavity tet before pushing it
 * @param {Cavity} cavity
 * @param {number} a
 * @param {number} b
 * @param {number} c
 * @param {number} d
 * @param {number} neighbour
 * @param {number[]} points
 * @param {function(problem:string):*} consumer
 */
export function push_boundary_with_validation(points, cavity, a, b, c, d, neighbour, consumer = console.warn) {
    let valid = true;
    const vol = tetrahedron_compute_signed_volume(points, a, b, c, d);

    if (vol < 0) {
        consumer(`Pushing a negative volume(=${vol}) boundary tet ${[a, b, c, d].join(', ')}`);

        valid = false;
    }

    cavity.push_boundary(a, b, c, d, neighbour);

    return valid;
}
