/**
 * Merge abscissa values if the ordinate value is in a list of centroids
 * @param data - object containing 2 properties x and y
 * @param centroids - centroids
 * @param options - options
 * @returns merged points
 */
export function xyMergeByCentroids(data, centroids, options = {}) {
    const { window = 0.01 } = options;
    const mergedPoints = {
        x: Float64Array.from(centroids),
        y: new Float64Array(centroids.length).fill(0),
    };
    let originalIndex = 0;
    let mergedIndex = 0;
    while (originalIndex < data.x.length && mergedIndex < centroids.length) {
        const diff = data.x[originalIndex] - centroids[mergedIndex];
        if (Math.abs(diff) < window) {
            mergedPoints.y[mergedIndex] += data.y[originalIndex++];
        }
        else if (diff < 0) {
            originalIndex++;
        }
        else {
            mergedIndex++;
        }
    }
    return mergedPoints;
}
//# sourceMappingURL=xyMergeByCentroids.js.map