import * as Core from "@intelligentgraphics/ig.gfx.core";
import * as ThreeJS from "@intelligentgraphics/ig.gfx.threejs";
import * as Planning from "@intelligentgraphics/ig.gfx.planning";
import * as _ from "lodash";
var MAX_ROTATION_DIFF_DEG = 10;
export var closestWallWithRotation = function (id) {
    //var tWallId = IG_GFX_Planning.WallUtilities.closestWall(id);
    var walls = Planning.Environment.getInstance().getWalls();
    if (walls.length === 0) {
        return undefined;
    }
    var componentABB = ThreeJS.AbstractBoundingBox.CreateFromGfxId(id);
    var componentPoints = componentABB.getPoints();
    var distanceAvgToComponent = function (wallId) {
        return Planning.WallUtilities.distanceAverageOfPointsToWall(componentPoints, wallId);
    };
    var wallId = _(walls)
        .sortBy(distanceAvgToComponent)
        .filter(function (w) {
        return (Math.abs(Core.State.API.GetYRotation(id) -
            Core.State.API.GetYRotation(w)) < MAX_ROTATION_DIFF_DEG);
    })
        .head();
    return wallId;
};
