import { assert } from "../../../core/assert.js";
import { ensureGeometryBoundingBox } from "../util/ensureGeometryBoundingBox.js";

/**
 *
 * @param {THREE.Geometry} geometry
 * @param {Vector3} size
 * @param {Vector3} result
 */
export function scaleGeometryToBox(geometry, size, result) {
    assert.notEqual(geometry, undefined, "Geometry is undefined");
    assert.notEqual(geometry, null, "Geometry is null");

    const boundingBox = ensureGeometryBoundingBox(geometry);

    //box size
    const actualBoxSize = boundingBox.max.clone().sub(boundingBox.min);
    const scale = Math.min(size.x / actualBoxSize.x, size.y / actualBoxSize.y, size.z / actualBoxSize.z);

    result.set(scale, scale, scale);

    return actualBoxSize.multiplyScalar(scale);
}
