import { v3_angle_between } from "../vec3/v3_angle_between.js";

/**
 * Compute 3d bounds of a circle in 3d space
 * NOTE: based on https://stackoverflow.com/questions/2592011/bounding-boxes-for-circle-and-arcs-in-3d
 * @param {AABB3} result
 * @param {number} centerX
 * @param {number} centerY
 * @param {number} centerZ
 * @param {number} normalX orientation of the circle
 * @param {number} normalY orientation of the circle
 * @param {number} normalZ orientation of the circle
 * @param {number} radius
 */
export function compute_circle_bounding_box(
    result,
    centerX, centerY, centerZ,
    normalX, normalY, normalZ,
    radius
) {

    const ax = v3_angle_between(normalX, normalY, normalZ, 1, 0, 0);
    const ay = v3_angle_between(normalX, normalY, normalZ, 0, 1, 0);
    const az = v3_angle_between(normalX, normalY, normalZ, 0, 0, 1);

    const rX = Math.sin(ax) * radius;
    const rY = Math.sin(ay) * radius;
    const rZ = Math.sin(az) * radius;

    result.setBounds(
        centerX - rX, centerY - rY, centerZ - rZ,
        centerX + rX, centerY + rY, centerZ + rZ
    );

}
