var _MatrixHelper = /** @class */ (function () {
    function _MatrixHelper(m11, m12, m21, m22, offsetX, offSetY) {
        this._m11 = m11;
        this._m12 = m12;
        this._m21 = m21;
        this._m22 = m22;
        this._offsetX = offsetX;
        this._offsetY = offSetY;
        this._type = _MatrixTypes.Unknown;
        this._checkMatrixType();
    }
    _MatrixHelper.prototype._scale = function (scaleX, scaleY, centerX, centerY) {
        var scalingMatrix = new _MatrixHelper(scaleX, 0, 0, scaleY, centerX, centerY);
        var resultMatrix = scalingMatrix._multiply(this);
        return resultMatrix;
    };
    _MatrixHelper.prototype._clone = function () {
        var matrix = new _MatrixHelper(this._m11, this._m12, this._m21, this._m22, this._offsetX, this._offsetY);
        return matrix;
    };
    _MatrixHelper.prototype._setMatrix = function (m11, m12, m21, m22, offsetX, offsetY, type) {
        this._m11 = m11;
        this._m12 = m12;
        this._m21 = m21;
        this._m22 = m22;
        this._offsetX = offsetX;
        this._offsetY = offsetY;
        this._type = type;
    };
    _MatrixHelper.prototype._translate = function (offsetX, offsetY) {
        if (this._type === _MatrixTypes.Identity) {
            this._setMatrix(1.0, 0.0, 0.0, 1.0, offsetX, offsetY, _MatrixTypes.Translation);
        }
        else {
            if (this._type === _MatrixTypes.Unknown) {
                this._offsetX += offsetX;
                this._offsetY += offsetY;
            }
            else {
                this._offsetX += offsetX;
                this._offsetY += offsetY;
                this._type |= _MatrixTypes.Translation;
            }
        }
        return this;
    };
    _MatrixHelper.prototype._transform = function (x, y) {
        var x2 = x * this._m11 + y * this._m21 + this._offsetX;
        var y2 = x * this._m12 + y * this._m22 + this._offsetY;
        return [x2, y2];
    };
    _MatrixHelper.prototype._multiply = function (matrix) {
        return new _MatrixHelper(this._m11 * matrix._m11 + this._m12 * matrix._m21, this._m11 * matrix._m12 + this._m12 * matrix._m22, this._m21 * matrix._m11 + this._m22 * matrix._m21, this._m21 * matrix._m12 + this._m22 * matrix._m22, this._offsetX * matrix._m11 + this._offsetY * matrix._m21 + matrix._offsetX, this._offsetX * matrix._m12 + this._offsetY * matrix._m22 + matrix._offsetY);
    };
    Object.defineProperty(_MatrixHelper.prototype, "_identity", {
        get: function () {
            return new _MatrixHelper(1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
        },
        enumerable: true,
        configurable: true
    });
    _MatrixHelper.prototype._checkMatrixType = function () {
        this._type = _MatrixTypes.Identity;
        if (this._m21 !== 0.0 || this._m12 !== 0.0) {
            this._type = _MatrixTypes.Unknown;
            return;
        }
        if (this._m11 !== 1.0 || this._m22 !== 1.0) {
            this._type = _MatrixTypes.Scaling;
        }
        if (this._offsetX !== 0.0 || this._offsetY !== 0.0) {
            this._type |= _MatrixTypes.Translation;
        }
        if ((this._getTypeIndex(this._type) & 3) === this._getTypeIndex(_MatrixTypes.Identity)) {
            this._type = _MatrixTypes.Identity;
        }
    };
    _MatrixHelper.prototype._getTypeIndex = function (type) {
        switch (type) {
            case _MatrixTypes.Identity:
                return 0;
            case _MatrixTypes.Translation:
                return 1;
            case _MatrixTypes.Scaling:
                return 2;
            case _MatrixTypes.scalingAndTranslation:
                return 3;
            case _MatrixTypes.Unknown:
                return 4;
        }
    };
    return _MatrixHelper;
}());
export { _MatrixHelper };
var _TransformationStack = /** @class */ (function () {
    function _TransformationStack(initialTransform) {
        this._currentTransform = new _MatrixHelper(1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
        this._transformStack = [];
        if (!initialTransform) {
            this._initialTransform = new _MatrixHelper(1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
        }
        else {
            this._initialTransform = initialTransform;
        }
    }
    Object.defineProperty(_TransformationStack.prototype, "_CurrentTransform", {
        get: function () {
            if (this._transformStack.length === 0) {
                return this._initialTransform;
            }
            return this._multiplyMatrices(this._currentTransform, this._initialTransform);
        },
        enumerable: true,
        configurable: true
    });
    _TransformationStack.prototype._pushTransform = function (transformMatrix) {
        this._transformStack.push(transformMatrix);
        var matrix = new _MatrixHelper(1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
        for (var _i = 0, _a = this._transformStack; _i < _a.length; _i++) {
            var current = _a[_i];
            matrix = this._multiplyMatrices(matrix, current);
        }
        this._currentTransform = matrix;
    };
    _TransformationStack.prototype._popTransform = function () {
        this._transformStack.pop();
        var matrix = new _MatrixHelper(1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
        for (var _i = 0, _a = this._transformStack; _i < _a.length; _i++) {
            var current = _a[_i];
            matrix = this._multiplyMatrices(matrix, current);
        }
        this._currentTransform = matrix;
    };
    _TransformationStack.prototype._clear = function () {
        this._transformStack = [];
    };
    _TransformationStack.prototype._multiplyMatrices = function (matrix1, matrix2) {
        return matrix1._multiply(matrix2);
    };
    return _TransformationStack;
}());
export { _TransformationStack };
var _MatrixTypes;
(function (_MatrixTypes) {
    _MatrixTypes[_MatrixTypes["Identity"] = 0] = "Identity";
    _MatrixTypes[_MatrixTypes["Scaling"] = 1] = "Scaling";
    _MatrixTypes[_MatrixTypes["Translation"] = 2] = "Translation";
    _MatrixTypes[_MatrixTypes["scalingAndTranslation"] = 3] = "scalingAndTranslation";
    _MatrixTypes[_MatrixTypes["Unknown"] = 4] = "Unknown";
})(_MatrixTypes || (_MatrixTypes = {}));
