"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var _ = tslib_1.__importStar(require("lodash"));
var SnapMatch_1 = require("./SnapMatch");
exports.SnapMatch = SnapMatch_1.SnapMatch;
var WeakSnapMatch_1 = require("./WeakSnapMatch");
exports.WeakSnapMatch = WeakSnapMatch_1.WeakSnapMatch;
var WallMatch_1 = require("./WallMatch");
exports.WallMatch = WallMatch_1.WallMatch;
var StrongChildMatch_1 = require("./StrongChildMatch");
exports.StrongChildMatch = StrongChildMatch_1.StrongChildMatch;
var StrongNeighborMatch_1 = require("./StrongNeighborMatch");
exports.StrongNeighborMatch = StrongNeighborMatch_1.StrongNeighborMatch;
var ScreenBasedChildMatch_1 = require("./ScreenBasedChildMatch");
exports.ScreenBasedChildMatch = ScreenBasedChildMatch_1.ScreenBasedChildMatch;
var BestMatch_1 = require("../../BestMatch");
/**
 * groups matches by rounded distance values and evaluates the best match per group
 * @param matches
 */
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_1.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_1.BestMatch(group);
        var bestMatch = matchMaker.best();
        result.push(bestMatch);
    }
    return result;
}
exports.removeRedundantMatches = removeRedundantMatches;
