import { v3_dot } from "../../vec3/v3_dot.js";

/**
 * Produces a numeric result to indicate which side of the plane the triangle is on
 * between +3 and -3:
 *      +3 means that all vertices ave above the plane
 *      -3 means all vertices are below the plane
 *      values in between indicate that the plane cuts through the triangle
 *
 * @param {number} plane_normal_x
 * @param {number} plane_normal_y
 * @param {number} plane_normal_z
 * @param {number} plane_constant
 * @param {number} ax
 * @param {number} ay
 * @param {number} az
 * @param {number} bx
 * @param {number} by
 * @param {number} bz
 * @param {number} cx
 * @param {number} cy
 * @param {number} cz
 * @returns {number}
 */
export function triangle_compute_plane_side(
    plane_normal_x, plane_normal_y, plane_normal_z, plane_constant,
    ax, ay, az,
    bx, by, bz,
    cx, cy, cz
) {
    let result = 0;

    // compute side for each point
    result += ( v3_dot(plane_normal_x, plane_normal_y, plane_normal_z, ax, ay, az) + plane_constant ) >= 0 ? 1 : -1;
    result += ( v3_dot(plane_normal_x, plane_normal_y, plane_normal_z, bx, by, bz) + plane_constant ) >= 0 ? 1 : -1;
    result += ( v3_dot(plane_normal_x, plane_normal_y, plane_normal_z, cx, cy, cz) + plane_constant ) >= 0 ? 1 : -1;

    return result;
}
