import * as _ from "lodash";
import { SnapMatch } from "./SnapMatch";
import { WeakSnapMatch } from "./WeakSnapMatch";
import { WallMatch } from "./WallMatch";
import { StrongChildMatch } from "./StrongChildMatch";
import { StrongNeighborMatch } from "./StrongNeighborMatch";
import { ScreenBasedChildMatch } from "./ScreenBasedChildMatch";
import { BestMatch } from "../../BestMatch";
export { SnapMatch, WeakSnapMatch, WallMatch, StrongChildMatch, StrongNeighborMatch, ScreenBasedChildMatch, };
/**
 * groups matches by rounded distance values and evaluates the best match per group
 * @param matches
 */
export function removeRedundantMatches(matches) {
    var similarMatchesGrouped;
    // if only screen based child matches are present, sort by screenDistance instead of xzDistance
    if (matches.every(function (match) { return match instanceof ScreenBasedChildMatch; })) {
        similarMatchesGrouped = _.groupBy(matches, function (m) {
            return m.distance.toFixed(2) + " " + m.screenDistance.toFixed(2);
        });
    }
    else {
        similarMatchesGrouped = _.groupBy(matches, function (m) { return m.distance.toFixed(2) + " " + m.xzDistance.toFixed(2); });
    }
    var result = new Array();
    for (var groupKey in similarMatchesGrouped) {
        var group = similarMatchesGrouped[groupKey];
        var matchMaker = new BestMatch(group);
        var bestMatch = matchMaker.best();
        result.push(bestMatch);
    }
    return result;
}
