import { modified_bessel_i0 } from "../../../../../core/math/modified_bessel_i0.js";
import { clamp } from "../../../../../core/math/clamp.js";

const PI2 = 2 * Math.PI;

const BASE_I0 = modified_bessel_i0(PI2);
const INV_BESSEL_I0 = 1 / BASE_I0;

/**
 * Support kernel size is 1
 * @see https://github.com/terifan/ImageResampler/blob/dbc212ce6aaa769bf3c9623cb6ead58ffd51d76c/src/org/terifan/image_resampler/FilterFactory.java#L815
 * @param {number} x
 * @returns {number}
 */
export function kaiser_1(x) {
    const i = clamp(x * 0.6666666666666666, -1.0, 1.0);

    const t = Math.sqrt(1 - i * i);

    return modified_bessel_i0(PI2 * t) * INV_BESSEL_I0;
}

kaiser_1.support = 1;
