/**
 *
 * @param {BinaryBuffer} buffer
 * @param {AABB3} box
 * @param {number} x0
 * @param {number} y0
 * @param {number} z0
 * @param {number} x1
 * @param {number} y1
 * @param {number} z1
 */
export function serializeAABB3Encoded_v0(buffer, box, x0, y0, z0, x1, y1, z1) {
    let header = 0;

    if (box.x0 === x0) {
        header |= 1;
    }

    if (box.x1 === x1) {
        header |= 2;
    }

    if (box.y0 === y0) {
        header |= 4;
    }

    if (box.y1 === y1) {
        header |= 8;
    }

    if (box.z0 === z0) {
        header |= 16;
    }

    if (box.z1 === z1) {
        header |= 32;
    }

    buffer.writeUint8(header);

    //compute value ranges
    const xD = x1 - x0;
    const yD = y1 - y0;
    const zD = z1 - z0;

    if ((header & 1) === 0) {
        const _x0 = Math.floor(((box.x0 - x0) / xD) * 65535);
        buffer.writeUint16(_x0);
    }

    if ((header & 2) === 0) {
        const _x1 = Math.ceil(((box.x1 - x0) / xD) * 65535);
        buffer.writeUint16(_x1);
    }

    if ((header & 4) === 0) {
        const _y0 = Math.floor(((box.y0 - y0) / yD) * 65535);
        buffer.writeUint16(_y0);
    }

    if ((header & 8) === 0) {
        const _y1 = Math.ceil(((box.y1 - y0) / yD) * 65535);
        buffer.writeUint16(_y1);
    }

    if ((header & 16) === 0) {
        const _z0 = Math.floor(((box.z0 - z0) / zD) * 65535);
        buffer.writeUint16(_z0);
    }

    if ((header & 32) === 0) {
        const _z1 = Math.ceil(((box.z1 - z0) / zD) * 65535);
        buffer.writeUint16(_z1);
    }
}
