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

const scratch_aabb = [];

export class BVHQueryIntersectsFrustum extends BVHQuery {

    /**
     * Collection of 6 planes: normal_x, normal_y, normal_z, offset
     * @type {number[]}
     */
    frustum = [];


    /**
     *
     * @param {number[]|ArrayLike<number>|Float32Array} frustum
     * @returns {BVHQueryIntersectsFrustum}
     */
    static from(frustum) {
        const r = new BVHQueryIntersectsFrustum();

        r.frustum = frustum;

        return r;
    }

    evaluate(node, tree) {

        tree.node_get_aabb(node, scratch_aabb);

        return aabb3_array_intersects_clipping_volume_array(scratch_aabb, 0, this.frustum, 0, 6);
    }
}
