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

/**
 *
 * @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} ref_x
 * @param {number} ref_y
 * @param {number} ref_z
 * @return {number}
 */
export function ray3_distance_to_point(
    origin_x, origin_y, origin_z,
    direction_x, direction_y, direction_z,
    ref_x, ref_y, ref_z
) {
    // find the closest point
    const sp0_x = ref_x - origin_x;
    const sp0_y = ref_y - origin_y;
    const sp0_z = ref_z - origin_z;

    //
    const d2 = v3_dot(direction_x, direction_y, direction_z, direction_x, direction_y, direction_z);
    const d3 = v3_dot(direction_x, direction_y, direction_z, sp0_x, sp0_y, sp0_z);

    return d3 / d2;
}
