// Die-level X/Y scatter points for two parametric tests — generalized from
// tsmap's own charts/aggregate.ts. Pure math, no DOM.
//
// Deliberate exception to the "prefer StatsSummary.stats.perTestStats over
// raw Die[]" dedup pattern used elsewhere in this package (same reasoning as
// correlation.ts): a scatter point is one die's paired (x, y) values across
// two tests, which per-test marginal summaries cannot provide. Always reads
// raw `Die[]`.
function scatterPointsForDies(dies, xTest, yTest, group, out) {
    for (const die of dies ?? []) {
        const x = die.testValues?.[xTest];
        const y = die.testValues?.[yTest];
        if (x !== undefined && y !== undefined && Number.isFinite(x) && Number.isFinite(y)) {
            out.push(group === undefined ? { x, y, hbin: die.hbin } : { x, y, hbin: die.hbin, group });
        }
    }
}
/** One point per die with valid values for both tests, across `items`. */
export function buildScatterData(items, xTest, yTest) {
    const points = [];
    for (const item of items)
        scatterPointsForDies(item.dies, xTest, yTest, undefined, points);
    return points;
}
/**
 * Scatter points tagged with their facet group, for colour-by-group scatter
 * (group replaces hard-bin colour). Unlike capability/boxplot's `groups`
 * (which restrict to one group at a time), every group's points are
 * returned together here — scatter never restricts, it colours.
 */
export function buildScatterDataGrouped(groups, xTest, yTest) {
    const points = [];
    for (const g of groups) {
        for (const item of g.items)
            scatterPointsForDies(item.dies, xTest, yTest, g.key, points);
    }
    return points;
}
//# sourceMappingURL=scatter.js.map