import { xyCheck } from "./xyCheck.js";
/**
 * Returns the numberMaxPoints points with the bigger y.
 * @param data - object that contains property x (an ordered increasing array) and y (an array).
 * @param numberMaxPoints - number of points to keep.
 * @returns the points filtered to keep the `numberMaxPoints` most intense points of the input.
 */
export function xyGetNMaxY(data, numberMaxPoints) {
    xyCheck(data);
    if (data.x.length <= numberMaxPoints) {
        return data;
    }
    else {
        const newX = new Float64Array(numberMaxPoints);
        const newY = new Float64Array(numberMaxPoints);
        const floatY = Float64Array.from(data.y);
        floatY.sort();
        floatY.reverse();
        const threshold = floatY[numberMaxPoints - 1];
        let index = 0;
        for (let i = 0; i < data.x.length; i++) {
            if (data.y[i] >= threshold) {
                newX[index] = data.x[i];
                newY[index] = data.y[i];
                index++;
            }
            if (index === numberMaxPoints) {
                return { x: newX, y: newY };
            }
        }
        return data;
    }
}
//# sourceMappingURL=xyGetNMaxY.js.map