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

/**
 * Get frustum corners from a set of planes
 * see {@link frustum_compute_corners} for a non-three.js version
 * @param {Float32Array|number[]} result
 * @param {Plane[]} planes
 */
export function computeFrustumCorners(result, planes) {

    const plane_x0 = planes[0];
    const plane_y0 = planes[2];
    const plane_z0 = planes[4];

    plane3_three_compute_convex_3_plane_intersection(result, 0,
        plane_x0,
        plane_y0,
        plane_z0
    );

    const plane_z1 = planes[5];

    plane3_three_compute_convex_3_plane_intersection(result, 3,
        plane_x0,
        plane_y0,
        plane_z1
    );

    const plane_y1 = planes[3];

    plane3_three_compute_convex_3_plane_intersection(result, 6,
        plane_x0,
        plane_y1,
        plane_z0
    );

    plane3_three_compute_convex_3_plane_intersection(result, 9,
        plane_x0,
        plane_y1,
        plane_z1
    );

    const plane_x1 = planes[1];

    plane3_three_compute_convex_3_plane_intersection(result, 12,
        plane_x1,
        plane_y0,
        plane_z0
    );

    plane3_three_compute_convex_3_plane_intersection(result, 15,
        plane_x1,
        plane_y0,
        plane_z1
    );

    plane3_three_compute_convex_3_plane_intersection(result, 18,
        plane_x1,
        plane_y1,
        plane_z0
    );

    plane3_three_compute_convex_3_plane_intersection(result, 21,
        plane_x1,
        plane_y1,
        plane_z1
    );
}
