"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var events_1 = require("events");
var constants_1 = require("./constants");
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
var matrix = svg.createSVGMatrix();
exports.onChange = new events_1.EventEmitter();
function translate(x, y, emitChanges) {
    if (emitChanges === void 0) { emitChanges = true; }
    matrix = matrix.translate(x, y);
    if (emitChanges)
        exports.onChange.emit(constants_1.TRANSLATE, x, y);
}
exports.translate = translate;
function scale(factor, emitChanges) {
    if (emitChanges === void 0) { emitChanges = true; }
    matrix = matrix.scale(factor);
    if (emitChanges)
        exports.onChange.emit(constants_1.SCALE, factor);
}
exports.scale = scale;
function rotate(radians, emitChanges) {
    if (emitChanges === void 0) { emitChanges = true; }
    var degrees = radians * 180 / Math.PI;
    matrix = matrix.rotate(degrees, degrees);
    if (emitChanges)
        exports.onChange.emit(constants_1.ROTATE, degrees);
}
exports.rotate = rotate;
function transformedPoint(x, y) {
    var pt = svg.createSVGPoint();
    pt.x = x;
    pt.y = y;
    return pt.matrixTransform(matrix.inverse());
}
exports.transformedPoint = transformedPoint;
function getMatrix() {
    return matrix;
}
exports.getMatrix = getMatrix;
function reset() {
    matrix = svg.createSVGMatrix();
    return exports.onChange.emit(constants_1.RESET);
}
exports.reset = reset;
function getDistance(touch1, touch2) {
    var a = touch1.clientX - touch2.clientX;
    var b = touch1.clientY - touch2.clientY;
    return Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
}
exports.getDistance = getDistance;
//# sourceMappingURL=utils.js.map