import { v3_morton_encode_normalized } from "./v3_morton_encode_normalized.js";

/**
 * @param {number} x
 * @param {number} y
 * @param {number} z
 * @param {number[]|AABB3} bounds
 * @returns {number}
 */
export function v3_morton_encode_bounded(x, y, z, bounds) {

    const bounds_x0 = bounds[0];
    const bounds_y0 = bounds[1];
    const bounds_z0 = bounds[2];

    const bounds_x1 = bounds[3];
    const bounds_y1 = bounds[4];
    const bounds_z1 = bounds[5];

    const bounds_span_x = bounds_x1 - bounds_x0;
    const bounds_span_y = bounds_y1 - bounds_y0;
    const bounds_span_z = bounds_z1 - bounds_z0;

    return v3_morton_encode_normalized(
        (x - bounds_x0) / bounds_span_x,
        (y - bounds_y0) / bounds_span_y,
        (z - bounds_z0) / bounds_span_z
    );
}