import {aabb3_compute_half_surface_area} from "./aabb3_compute_half_surface_area.js";

/**
 * Compute surface area for a box contain both inputs
 * @param {AABB3} a
 * @param {AABB3} b
 * @returns {number}
 */
function aabb3_score_boxes_SAH(a, b) {
    
    // read out bounds

    const ax0 = a.x0;
    const ay0 = a.y0;
    const az0 = a.z0;
    const ax1 = a.x1;
    const ay1 = a.y1;
    const az1 = a.z1;

    const bx0 = b.x0;
    const by0 = b.y0;
    const bz0 = b.z0;
    const bx1 = b.x1;
    const by1 = b.y1;
    const bz1 = b.z1;

    // compute combined bounds

    const x0 = ax0 < bx0 ? ax0 : bx0;
    const y0 = ay0 < by0 ? ay0 : by0;
    const z0 = az0 < bz0 ? az0 : bz0;

    const x1 = ax1 > bx1 ? ax1 : bx1;
    const y1 = ay1 > by1 ? ay1 : by1;
    const z1 = az1 > bz1 ? az1 : bz1;

    //

    return aabb3_compute_half_surface_area(x0, y0, z0, x1, y1, z1);
}

export {aabb3_score_boxes_SAH};
