import * as Core from "@intelligentgraphics/ig.gfx.core";
import { WallUtilities } from "../WallUtilities";
import { LinearAlgebra, MathTypes, } from "@intelligentgraphics/ig.gfx.core";
import WorldLocalConverter from "../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;
}());
export { 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.faces(wallId).front;
        this.plane = 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 = LinearAlgebra.DistanceToPlaneSegment(this.frontFace, p);
        return this.wallComponent.isVisible && distance <= 0.1;
    };
    return WallPlane;
}());
export { 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(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 = 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 = LinearAlgebra.DistanceToPlaneSegment(this.planeSegment, p);
        return distance <= 0.1;
    };
    return NonEnvironmentWallPlane;
}());
export { NonEnvironmentWallPlane };
