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

/**
 *
 * @param {number[]} result
 * @param {number} origin_x
 * @param {number} origin_y
 * @param {number} origin_z
 * @param {number} direction_x
 * @param {number} direction_y
 * @param {number} direction_z
 * @param {number[]|ArrayLike<number>|Uint32Array} indices
 * @param {number} triangle_index
 * @param {number[]|Float32Array} positions
 * @return {boolean}
 */
export function computeTriangleRayIntersectionBarycentricGeometry(
    result,
    origin_x, origin_y, origin_z,
    direction_x, direction_y, direction_z,
    indices, triangle_index, positions
) {
    const index_offset = triangle_index * 3;

    const a = indices[index_offset];
    const b = indices[index_offset + 1];
    const c = indices[index_offset + 2];


    const a_address = a * 3;
    const b_address = b * 3;
    const c_address = c * 3;


    const ax = positions[a_address];
    const ay = positions[a_address + 1];
    const az = positions[a_address + 2];

    const bx = positions[b_address];
    const by = positions[b_address + 1];
    const bz = positions[b_address + 2];

    const cx = positions[c_address];
    const cy = positions[c_address + 1];
    const cz = positions[c_address + 2];

    return computeTriangleRayIntersectionBarycentric(
        result,
        origin_x, origin_y, origin_z,
        direction_x, direction_y, direction_z,
        ax, ay, az,
        bx, by, bz,
        cx, cy, cz
    );
}