import { Miniball } from "../../../core/geom/packing/miniball/Miniball.js";
import { PointSet } from "../../../core/geom/packing/miniball/PointSet.js";

/**
 * @typedef Vector4Like {{set:function(x:number,y:number,z:number,w:number):void}}
 *
 */

/**
 *
 * @param {Float32Array} positions
 * @param {Vector4|Vector4Like} result
 */
export function computeBoundingSphereFromVertexData(positions, result) {

    const pointSet = new PointSet(positions.length / 3, 3, positions);
    const miniball = new Miniball(pointSet);

    const aCenter = miniball.center();
    const radius = miniball.radius();

    result.set(
        aCenter[0],
        aCenter[1],
        aCenter[2],
        radius
    );

}