import { aabb3_detailed_volume_intersection } from "../../geom/3d/aabb/aabb3_detailed_volume_intersection.js";


/**
 *
 * @type {number[]}
 */
const scratch_points_data = [];

/**
 * Figures out intersection volume between an AABB and a frustum for much tighter bounds
 *
 * Especially beneficial when trying to intersect a large AABB against a small frustum,
 * where where traditionally only AABB corners would be considered,
 * we're instead able to compute minimum bounds of the overlap of the two
 *
 * @param {number} x0
 * @param {number} y0
 * @param {number} z0
 * @param {number} x1
 * @param {number} y1
 * @param {number} z1
 * @param {number[]} planes
 * @param {number} plane_count
 * @param {number} plane_mask
 * @param {function(x:number,y:number,z:number)} callback
 * @param {*} [thisArg]
 */
export function aabb3_detailed_volume_intersection_callback_based(
    x0, y0, z0, x1, y1, z1,
    plane_mask,
    planes,
    plane_count,
    callback,
    thisArg
) {
    const point_count = aabb3_detailed_volume_intersection(
        scratch_points_data, 0,
        x0, y0, z0, x1, y1, z1,
        plane_mask,
        planes,
        plane_count
    );

    for (let i = 0; i < point_count; i++) {

        const address = i * 3;

        const x = scratch_points_data[address];
        const y = scratch_points_data[address + 1];
        const z = scratch_points_data[address + 2];

        callback.call(thisArg,
            x,
            y,
            z
        );

        // Gizmo.color= [1,1,1,1];
        // Gizmo.draw_solid_sphere([x, y, z], 0.1);
    }
}

