"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Core = tslib_1.__importStar(require("@intelligentgraphics/ig.gfx.core"));
var THREE = tslib_1.__importStar(require("@intelligentgraphics/three"));
/** Class for converting between local and world coordinate system of an object */
var WorldLocalConverter = /** @class */ (function () {
    function WorldLocalConverter(id) {
        this.component = Core.State.API.GetComponent(id);
        this.scaling = Core.State.API.GetScaling(id);
    }
    /**
     * Transform WorldCoordinates to LocalCoordinates
     * @param point
     * @returns {Vector3}
     */
    WorldLocalConverter.prototype.toLocal = function (point) {
        this.scaleEqually();
        var inLocalCoordinates = this.component.worldToLocal(new THREE.Vector3(point.x, point.y, point.z));
        this.restoreScaling();
        return inLocalCoordinates;
    };
    /**
     * Transform LocalCoordinates to WorldCoordinates
     * @param point
     * @returns {Vector3}
     */
    WorldLocalConverter.prototype.toWorld = function (point) {
        this.scaleEqually();
        var inWorldCoordinates = this.component.localToWorld(new THREE.Vector3(point.x, point.y, point.z));
        this.restoreScaling();
        return inWorldCoordinates;
    };
    /**
     * For consistent results even with scaled objects (e.g. niches) we provide two functions: one for setting the scaling
     * to an equal 1,1,1 (to be called before calculations) and one the restore the scaling (to be called after calculations are finished)
     */
    WorldLocalConverter.prototype.restoreScaling = function () {
        Core.State.API.SetScaling(this.component.name, this.scaling);
    };
    WorldLocalConverter.prototype.scaleEqually = function () {
        Core.State.API.SetScaling(this.component.name, { x: 1, y: 1, z: 1 });
    };
    return WorldLocalConverter;
}());
exports.default = WorldLocalConverter;
