import { computeGeometryBoundingSphereMiniball } from "./computeGeometryBoundingSphereMiniball.js";
import { Sphere as ThreeSphere, Vector3 as ThreeVector3 } from "three";

/**
 *
 * @param {BufferGeometry} geometry
 * @returns {Sphere}
 */
export function ensureGeometryBoundingSphere(geometry) {
    let boundingSphere = geometry.boundingSphere;

    if (boundingSphere === null || boundingSphere === undefined) {
        //build up bounding sphere
        const vector4 = computeGeometryBoundingSphereMiniball(geometry);
        geometry.boundingSphere = new ThreeSphere(new ThreeVector3(vector4.x, vector4.y, vector4.z), vector4.w);
    }

    return boundingSphere;
}
