import { plane3_slerp } from "../../../../../core/geom/3d/plane/plane3_slerp.js";

/**
 *
 * @param {Float32Array|number[]} destination
 * @param {number} offset
 * @param {number} count number of slices
 * @param {Plane} plane_0
 * @param {Plane} plane_1
 * @returns {number}
 * @private
 */
export function write_cluster_planes(destination, offset, count, plane_0, plane_1) {
    let cursor = offset;

    const n_x0 = plane_0.normal.x;
    const n_y0 = plane_0.normal.y;
    const n_z0 = plane_0.normal.z;
    const p_d0 = plane_0.constant;

    const n_x1 = -plane_1.normal.x;
    const n_y1 = -plane_1.normal.y;
    const n_z1 = -plane_1.normal.z;
    const p_d1 = -plane_1.constant;

    const i_limit = count + 1;

    for (let i = 0; i < i_limit; i++) {
        const t = (i / count);

        plane3_slerp(
            destination,
            cursor,
            n_x0, n_y0, n_z0, p_d0,
            n_x1, n_y1, n_z1, p_d1,
            t
        );

        cursor += 4;
    }

    return cursor - offset;
}
