/**
 *
 * @param {BinaryBuffer} buffer
 * @param {number} x
 * @param {number} y
 * @param {number} z
 *
 * @author Alex Goldring
 * @copyright Company Named Limited (c) 2026
 */
export function v3_binary_equality_encode(buffer, x, y, z){

    let header = 0;

    if (x === y) {
        header |= 1;
    }

    if (y === z) {
        header |= 2;
    }

    if (x === z) {
        header |= 4;
    }

    if (header === 7) {
        if(x === 0){
            // all axes 0
            header |= 8;
        }else if(x === 1){
            // all axes 1
            header |= 16;
        }
    }

    buffer.writeUint8(header);

    if(header > 7){
        // special value encoded in the header
        return;
    }

    if ((header & 7) === 7) {
        //all components are the same
        buffer.writeFloat32(x);
    } else if (header === 1) {
        //X and Y are the same, Z is different
        buffer.writeFloat32(x);
        buffer.writeFloat32(z);
    } else if (header === 2) {
        //Y and Z are the same, X is different
        buffer.writeFloat32(x);
        buffer.writeFloat32(y);
    } else if (header === 4) {
        //X and Z are the same, Y is different
        buffer.writeFloat32(x);
        buffer.writeFloat32(y);
    } else {
        //scale components are different
        buffer.writeFloat32(x);
        buffer.writeFloat32(y);
        buffer.writeFloat32(z);
    }
}