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";
const MAX_ROTATION_DIFF_DEG = 10;
export const closestWallWithRotation = (id) => {
    //var tWallId = IG_GFX_Planning.WallUtilities.closestWall(id);
    const walls = Planning.Environment.getInstance().getWalls();
    if (walls.length === 0) {
        return undefined;
    }
    const componentABB = ThreeJS.AbstractBoundingBox.CreateFromGfxId(id);
    const componentPoints = componentABB.getPoints();
    const distanceAvgToComponent = (wallId) => Planning.WallUtilities.distanceAverageOfPointsToWall(componentPoints, wallId);
    const wallId = _(walls)
        .sortBy(distanceAvgToComponent)
        .filter(w => {
        return (Math.abs(Core.State.API.GetYRotation(id) -
            Core.State.API.GetYRotation(w)) < MAX_ROTATION_DIFF_DEG);
    })
        .head();
    return wallId;
};
