import { assert } from "../../../assert.js";
import v3_morton_encode from "./v3_morton_encode.js";

/**
 * Note: does not clamp, make sure that inputs are within 0..1 range.
 * @param {number} x value between 0 and 1
 * @param {number} y value between 0 and 1
 * @param {number} z value between 0 and 1
 * @returns {number} morton code
 */
export function v3_morton_encode_normalized(x, y, z) {
    assert.isNumber(x, 'x');
    assert.isNumber(y, 'y');
    assert.isNumber(z, 'z');

    // scale to 10 bits
    const ndc_x = 1023 * x;
    const ndc_y = 1023 * y;
    const ndc_z = 1023 * z;

    return v3_morton_encode(
        Math.round(ndc_x),
        Math.round(ndc_y),
        Math.round(ndc_z)
    );
}