"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Core = tslib_1.__importStar(require("@intelligentgraphics/ig.gfx.core"));
var WallUtilities_1 = require("../WallUtilities");
var ig_gfx_core_1 = require("@intelligentgraphics/ig.gfx.core");
var WorldLocalConverter_1 = tslib_1.__importDefault(require("../WorldLocalConverter"));
/** A standard plane which allows all points in the given plane for movement.  */
var StandardPlane = /** @class */ (function () {
    function StandardPlane(plane, isMainPlane) {
        if (isMainPlane === void 0) { isMainPlane = true; }
        this.plane = plane;
        this.isMainPlane = isMainPlane;
    }
    StandardPlane.prototype.isValid = function (p) {
        // no restriction on the points of the plane (except for undefined points)
        return !!p;
    };
    return StandardPlane;
}());
exports.StandardPlane = StandardPlane;
/** Class for movement at the front of a wall. Only valid points are points that are on the front face of the wall. */
var WallPlane = /** @class */ (function () {
    /**
     * The constructor
     * @param wallId
     * @param offset used for moving the plane, so that the movement is always exactly at the wall
     */
    function WallPlane(wallId, offset) {
        this.wallId = wallId;
        this.frontFace = WallUtilities_1.WallUtilities.faces(wallId).front;
        this.plane = ig_gfx_core_1.MathTypes.convertPlaneSegmentToPlane(this.frontFace);
        // adjust for mouse attachments away from the actual position
        this.plane.point = Core.Vector.Add3(this.plane.point, offset);
        // also adjust the front face so that distance calculation is easier later
        this.frontFace.point = Core.Vector.Add3(this.frontFace.point, offset);
        this.isMainPlane = true;
        this.wallComponent = Core.State.API.SetupWall(wallId);
    }
    WallPlane.prototype.isValid = function (p) {
        if (!p) {
            return false;
        }
        // if the point is too far above the wall, the point should be invalid
        var distance = ig_gfx_core_1.LinearAlgebra.DistanceToPlaneSegment(this.frontFace, p);
        return this.wallComponent.isVisible && distance <= 0.1;
    };
    return WallPlane;
}());
exports.WallPlane = WallPlane;
var NonEnvironmentWallPlane = /** @class */ (function () {
    function NonEnvironmentWallPlane(componentId, offset) {
        this.isMainPlane = true;
        var bounds = Core.State.API.GetBounds(componentId, "Local", true);
        var converter = new WorldLocalConverter_1.default(componentId);
        var frontLeft = {
            x: bounds.min.x,
            y: bounds.min.y,
            z: bounds.max.z,
        };
        this.planeSegment = {
            point: converter.toWorld(frontLeft),
            borderU: { x: 0, y: bounds.max.y - bounds.min.y, z: 0 },
            borderV: { x: bounds.max.x - bounds.min.x, y: 0, z: 0 },
        };
        this.plane = ig_gfx_core_1.MathTypes.convertPlaneSegmentToPlane(this.planeSegment);
        // adjust for mouse attachments away from the actual position
        this.plane.point = Core.Vector.Add3(this.plane.point, offset);
        // also adjust the front face so that distance calculation is easier later
        this.planeSegment.point = Core.Vector.Add3(this.planeSegment.point, offset);
    }
    NonEnvironmentWallPlane.prototype.isValid = function (p) {
        if (!p) {
            return false;
        }
        var distance = ig_gfx_core_1.LinearAlgebra.DistanceToPlaneSegment(this.planeSegment, p);
        return distance <= 0.1;
    };
    return NonEnvironmentWallPlane;
}());
exports.NonEnvironmentWallPlane = NonEnvironmentWallPlane;
