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

/**
 * Multidimensional axis-aligned bounding box calculation
 * @param {number[]} result
 * @param {number[]|ArrayLike<number>} input
 * @param {number} input_offset
 * @param {number} input_count
 * @param {number} d number of dimensions
 */
export function compute_aabb_from_points(
    result,
    input,
    input_offset,
    input_count,
    d
) {

    let i = 0;
    let j = 0;

    for (; i < d; i++) {
        result[i] = Infinity;
        result[i + d] = -Infinity;
    }

    for (i = 0; i < input_count; i++) {

        const offset_0 = input_count + i * d;

        for (j = 0; j < d; j++) {
            const v = input[offset_0 + j];

            result[j] = min2(result[j], v);
            result[j + d] = max2(result[j + d], v);
        }
    }
}
