import { split_by_3 } from "../../../binary/split_by_3.js";

/**
 * Based on article and C++ source code:
 *      https://www.forceflow.be/2013/10/07/morton-encodingdecoding-through-bit-interleaving-implementations/
 *      https://github.com/Forceflow/libmorton/blob/main/libmorton/morton3D.h
 *
 * @param {number} x
 * @param {number} y
 * @param {number} z
 * @returns {number}
 */
export function mortonEncode_magicbits(x, y, z) {

    const x_bits = split_by_3(x);
    const y_bits = split_by_3(y) << 1;
    const z_bits = split_by_3(z) << 2;

    return x_bits | y_bits | z_bits;
}
