/**
 * Compute squared radius of bonding sphere centered on 0,0,0 from a set of points and a transform matrix that is to be applied to the points prior to calculation of bounds
 * @param {number[]|ArrayLike<number>} input
 * @param {number} input_length length of the input array, foe example if there is just 1 vector in the input, length will be 3
 * @param {ArrayLike<number>|number[]|Float32Array} mat4 4x4 transformation matrix
 * @returns {number}
 */
export function sphere_radius_sqr_from_v3_array_transformed(
    input,
    input_length,
    mat4
) {
    let result = 0;

    for (let i = 0; i < input_length; i += 3) {
        const x = input[i];
        const y = input[i + 1];
        const z = input[i + 2];

        const _x = mat4[0] * x + mat4[4] * y + mat4[8] * z + mat4[12];
        const _y = mat4[1] * x + mat4[5] * y + mat4[9] * z + mat4[13];
        const _z = mat4[2] * x + mat4[6] * y + mat4[10] * z + mat4[14];

        const l2 = _x * _x + _y * _y + _z * _z;

        if (l2 > result) {
            result = l2;
        }
    }

    return result;
}
