import { xMedian } from "../x/xMedian.js";
/**
 * Computes the median of Y values in a sliding window around each point.
 * @param data - object with x and y arrays of the same length.
 * @param options - options for the median computation.
 * @returns A new DataXY with the same x values and smoothed y values.
 */
export function xyMedianY(data, options = {}) {
    const { windowSize = 5 } = options;
    const { x, y } = data;
    const halfWindow = Math.floor(windowSize / 2);
    const result = new Float64Array(y.length);
    for (let i = 0; i < y.length; i++) {
        const fromIndex = Math.max(0, i - halfWindow);
        const toIndex = Math.min(y.length, i + halfWindow + 1);
        const window = ArrayBuffer.isView(y)
            ? y.subarray(fromIndex, toIndex)
            : y.slice(fromIndex, toIndex);
        result[i] = xMedian(window, { exact: false });
    }
    return { x, y: result };
}
//# sourceMappingURL=xyMedianY.js.map