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

/**
 * Project a point onto a plane
 * @param {Vector3} result
 * @param {number} point_x
 * @param {number} point_y
 * @param {number} point_z
 * @param {number} normal_x
 * @param {number} normal_y
 * @param {number} normal_z
 * @param {number} plane_offset
 */
export function plane3_project_point(
    result,
    point_x, point_y, point_z,
    normal_x, normal_y, normal_z, plane_offset
) {
    const distance = v3_distance_above_plane(point_x, point_y, point_z, normal_x, normal_y, normal_z, plane_offset);

    const negative_distance = -distance;

    const x = normal_x * negative_distance + point_x;
    const y = normal_y * negative_distance + point_y;
    const z = normal_z * negative_distance + point_z;

    result.set(x, y, z);
}
