import { insphere } from "robust-predicates";

/**
 * Approximate 3D insphere test. Robust
 *
 *
 * @param {number[]} points
 * @param {number} a tetrahedral point index
 * @param {number} b tetrahedral point index
 * @param {number} c tetrahedral point index
 * @param {number} d tetrahedral point index
 * @param {number} e reference point index that we are testing against the tetrahedron
 * @returns {number}
 */
export function in_sphere3d_robust(
    points,
    a, b, c, d,
    e
) {

    const a3 = a * 3;
    const b3 = b * 3;
    const c3 = c * 3;
    const d3 = d * 3;
    const e3 = e * 3;

    const ax = points[a3];
    const ay = points[a3 + 1];
    const az = points[a3 + 2];

    const bx = points[b3];
    const by = points[b3 + 1];
    const bz = points[b3 + 2];

    const cx = points[c3];
    const cy = points[c3 + 1];
    const cz = points[c3 + 2];

    const dx = points[d3];
    const dy = points[d3 + 1];
    const dz = points[d3 + 2];

    const ex = points[e3];
    const ey = points[e3 + 1];
    const ez = points[e3 + 2];

    return -insphere(
        ax, ay, az,
        bx, by, bz,
        cx, cy, cz,
        dx, dy, dz,
        ex, ey, ez
    );
}
