/**
 * Computes common x slots from multiple DataXY spectra by grouping nearby x values.
 * @param data - data.
 * @param options - options.
 */
export function getSlots(data, options = {}) {
    const { delta = 1 } = options;
    const deltaIsFunction = typeof delta === 'function';
    const possibleXs = Float64Array.from(data.flatMap((spectrum) => spectrum.x));
    possibleXs.sort();
    if (possibleXs.length === 0) {
        throw new Error('can not process empty arrays');
    }
    let currentSlot = {
        from: possibleXs[0],
        to: possibleXs[0],
        average: possibleXs[0],
        sum: possibleXs[0],
        number: 1,
    };
    const slots = [currentSlot];
    for (let i = 1; i < possibleXs.length; i++) {
        const currentDelta = deltaIsFunction ? delta(possibleXs[i]) : delta;
        if (possibleXs[i] - currentSlot.to <= currentDelta) {
            currentSlot.to = possibleXs[i];
            currentSlot.number++;
            currentSlot.sum += possibleXs[i];
            currentSlot.average = currentSlot.sum / currentSlot.number;
        }
        else {
            currentSlot = {
                from: possibleXs[i],
                to: possibleXs[i],
                average: possibleXs[i],
                sum: possibleXs[i],
                number: 1,
            };
            slots.push(currentSlot);
        }
    }
    return slots;
}
//# sourceMappingURL=getSlots.js.map