const ONE_OVER_SIX = 1.0 / 6.0;

/**
 * Compute signed volume of a tetrahedron with the last point at the origin
 * Triangle is defined by points A,B,C
 * @see "EFFICIENT FEATURE EXTRACTION FOR 2D/3D OBJECTS IN MESH REPRESENTATION" by Cha Zhang and Tsuhan Chen
 * @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
 * @return {number}
 */
export function triangle_compute_signed_volume(
    ax, ay, az,
    bx, by, bz,
    cx, cy, cz
) {

    const v321 = cx * by * az;
    const v231 = bx * cy * az;
    const v312 = cx * ay * bz;
    const v132 = ax * cy * bz;
    const v213 = bx * ay * cz;
    const v123 = ax * by * cz;

    return ONE_OVER_SIX * (-v321 + v231 + v312 - v132 - v213 + v123);

}