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


/**
 * evaluate the basis functions
 * shBasis is an Array[ 9 ]
 *
 * @param {number} x
 * @param {number} y
 * @param {number} z
 * @param {number[]|ArrayLike<number>|Float32Array|Float64Array} output output is written here
 */
export function sh3_basis_at(x, y, z, output) {

    assert.isNumber(x,'x');
    assert.notNaN(x,'x');

    assert.isNumber(y,'y');
    assert.notNaN(y,'y');

    assert.isNumber(z,'z');
    assert.notNaN(z,'z');

    // normal is assumed to be unit length


    // band 0
    output[0] = 0.28209479177387814;

    // band 1
    output[1] = 0.4886025119029199 * y;
    output[2] = 0.4886025119029199 * z;
    output[3] = 0.4886025119029199 * x;

    // band 2
    output[4] = 1.0925484305920792 * x * y;
    output[5] = 1.0925484305920792 * y * z;
    output[6] = 0.31539156525252005 * (3 * z * z - 1);
    output[7] = 1.0925484305920792 * x * z;
    output[8] = 0.5462742152960396 * (x * x - y * y);

}
