"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ProcessFurtherOperation_1 = require("./ProcessFurtherOperation");
/** Class for adapting a movement to a rotation grid */
var GridRotationOperation = /** @class */ (function (_super) {
    tslib_1.__extends(GridRotationOperation, _super);
    function GridRotationOperation(preceedingOperation, rotationGrid) {
        var _this = _super.call(this, preceedingOperation) || this;
        _this.rotationGrid = rotationGrid;
        return _this;
    }
    GridRotationOperation.prototype.processMotionResult = function (resultParam) {
        var _this = this;
        var result = tslib_1.__assign(tslib_1.__assign({}, resultParam), { transformations: resultParam.transformations.map(function (trafo) {
                return _this.adaptToGrid(trafo);
            }) });
        return result;
    };
    GridRotationOperation.prototype.processEndResult = function (resultParam) {
        var _this = this;
        var result = tslib_1.__assign(tslib_1.__assign({}, resultParam), { transformations: resultParam.transformations.map(function (trafo) {
                return _this.adaptToGrid(trafo);
            }) });
        return result;
    };
    /**
     * Adapt all three rotation components to the grid
     * @param transformation
     * @returns {Core.Transformation}
     */
    GridRotationOperation.prototype.adaptToGrid = function (transformation) {
        return tslib_1.__assign(tslib_1.__assign({}, transformation), { rotation: {
                x: this.closestOnGrid(transformation.rotation.x),
                y: this.closestOnGrid(transformation.rotation.y),
                z: this.closestOnGrid(transformation.rotation.z),
            } });
    };
    GridRotationOperation.prototype.closestOnGrid = function (angle) {
        return Math.round(angle / this.rotationGrid) * this.rotationGrid;
    };
    return GridRotationOperation;
}(ProcessFurtherOperation_1.ProcessFurtherOperation));
exports.GridRotationOperation = GridRotationOperation;
