/**
 *
 * @param {number[]} output
 * @param {number[]} indices
 * @param {number[]} positions
 * @param {number} face_index
 * @param {number} t
 * @param {number} u
 * @param {number} v
 */
export function construct_ray_hit_from_geometry(
    output,
    indices, positions,
    face_index,
    t, u, v
) {

    const index_offset = face_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];

    // normal

    // edge1 = a - b
    const edge1_x = bx - ax;
    const edge1_y = by - ay;
    const edge1_z = bz - az;

    // edge2 = c - a
    const edge2_x = cx - ax;
    const edge2_y = cy - ay;
    const edge2_z = cz - az;

    // compute position of intersection point
    output[0] = ax + edge1_x * u + edge2_x * v;
    output[1] = ay + edge1_y * u + edge2_y * v;
    output[2] = az + edge1_z * u + edge2_z * v;

    // Compute triangle normal

    // normal = edge1 x edge2
    const normal_x = edge1_y * edge2_z - edge1_z * edge2_y;
    const normal_y = edge1_z * edge2_x - edge1_x * edge2_z;
    const normal_z = edge1_x * edge2_y - edge1_y * edge2_x

    output[3] = normal_x;
    output[4] = normal_y;
    output[5] = normal_z;

    output[6] = t;
    output[7] = u;
    output[8] = v;
    output[9] = face_index;
}