//

import { assert } from "../../../assert.js";
import { max2 } from "../../../math/max2.js";
import { min2 } from "../../../math/min2.js";

/**
 * Merge bounds of two axis-aligned bounding boxes, the result is a box that tightly bounds inputs
 * @param {ArrayLike<number>|number[]|Float32Array} result where resulting value is written to
 * @param {number} result_offset
 * @param {ArrayLike<number>|number[]|Float32Array} a
 * @param {number} a_offset
 * @param {ArrayLike<number>|number[]|Float32Array} b
 * @param {number} b_offset
 */
export function aabb3_array_combine(
    result, result_offset,
    a, a_offset,
    b, b_offset
) {

    assert.isNumber(a_offset,'a_offset');
    assert.notNaN(a_offset,'a_offset');
    assert.isNonNegativeInteger(a_offset, 'a_offset');

    assert.isNumber(b_offset,'b_offset');
    assert.notNaN(a_offset,'b_offset');
    assert.isNonNegativeInteger(b_offset, 'b_offset');

    const ax0 = a[a_offset + 0];
    const ay0 = a[a_offset + 1];
    const az0 = a[a_offset + 2];
    const ax1 = a[a_offset + 3];
    const ay1 = a[a_offset + 4];
    const az1 = a[a_offset + 5];

    const bx0 = b[b_offset + 0];
    const by0 = b[b_offset + 1];
    const bz0 = b[b_offset + 2];
    const bx1 = b[b_offset + 3];
    const by1 = b[b_offset + 4];
    const bz1 = b[b_offset + 5];

    const x0 = min2(ax0, bx0);
    const y0 = min2(ay0, by0);
    const z0 = min2(az0, bz0);

    const x1 = max2(ax1, bx1);
    const y1 = max2(ay1, by1);
    const z1 = max2(az1, bz1);

    result[result_offset + 0] = x0;
    result[result_offset + 1] = y0;
    result[result_offset + 2] = z0;

    result[result_offset + 3] = x1;
    result[result_offset + 4] = y1;
    result[result_offset + 5] = z1;

}
