import { createDoubleArray } from "../utils/createArray.js";
/**
 * This function make a zero filling to re and im part.
 * @param data - object of kind {re:[], im:[]}
 * @param totalLength - final number of points
 * @returns new DataReIm object with zero-filled,
 * truncated arrays if totalLength is smaller current length or
 * the same input if totalLength is equal that current length
 */
export function reimZeroFilling(data, totalLength) {
    if (!Number.isInteger(totalLength) || totalLength < 0) {
        throw new RangeError('totalLength must be a non-negative integer');
    }
    const { re, im } = data;
    const length = re.length;
    if (totalLength === 0 || length === totalLength)
        return data;
    if (length > totalLength) {
        return {
            re: re.slice(0, totalLength),
            im: im.slice(0, totalLength),
        };
    }
    const newRE = createDoubleArray(re.constructor, totalLength);
    const newIM = createDoubleArray(im.constructor, totalLength);
    for (let i = 0; i < re.length; i++) {
        newRE[i] = re[i];
        newIM[i] = im[i];
    }
    return {
        re: newRE,
        im: newIM,
    };
}
//# sourceMappingURL=reimZeroFilling.js.map