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

/**
 *
 * @param {Float32Array} kernel
 * @param {number} sample_count
 * @param {number} sigma
 */
export function build_gaussian_kernel_1d(kernel, sample_count, sigma) {

    const half_width = (sample_count - 1) * 0.5;

    let kernel_power_sum = 0;
    for (let i = 0; i < sample_count; i++) {
        const local = i - half_width;

        const power = gaussian(sigma, local);
        kernel[i] = power;
        kernel_power_sum += power;
    }

    // normalize kernel
    for (let i = 0; i < sample_count; i++) {
        kernel[i] /= kernel_power_sum;
    }
}