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

const scratch_aabb = [];

export class BVHQueryIntersectsRay extends BVHQuery {
    /**
     *
     * @type {number[]}
     */
    ray = [];

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

        r.ray = ray;

        return r;
    }

    evaluate(node, tree) {

        tree.node_get_aabb(node, scratch_aabb);

        // test node against the ray
        return aabb3_array_intersects_ray_array(
            scratch_aabb,
            this.ray
        );
    }
}