Source: common/util/transformations.js

/**
 * Internal utilities for working with CSS transformations.
 * @name Transformations
 * @namespace
 * @private
 */
define(["lib/jquery", "lib/sylvester", "lib/decompose"],
function($,            Sylvester,       decompose) {

    "use strict";

    // given x, y, and a 3D transform (as a 16-element array), returns
    // {x: <int>, y: <int>} of the transformed point projected into 2D space.
    // var transformPoint = function(x, y, t) {
    //     var vector = Sylvester.$V([x, y, 0, 1]);
    //     var matrix = Sylvester.$M([[ t[0],  t[1],  t[2],  t[3]  ],
    //                                [ t[4],  t[5],  t[6],  t[7]  ],
    //                                [ t[8],  t[9],  t[10], t[11] ],
    //                                [ t[12], t[13], t[14], t[15] ]]);
    //
    //     var transformed = matrix.multiply(vector);
    //     return {x: transformed.e(1), y: transformed.e(2)}
    // }

    var Transformations = /** @lends Transformations */ {
        /**
         * Given a 16-element array representing a 3-D trasform, decomposes
         * it to a CSSMatrixDecomposed with the following properties:
         * 
         *     var decomposed = Transformations.decompose(someArray)
         *     decomposed.perspective // => {x: <int>, y: <int>, z: <int>, w: <int>}
         *     decomposed.translate   // => {x: <int>, y: <int>, z: <int>}
         *     decomposed.rotate      // => {x: <int>, y: <int>, z: <int>} (radians)
         *     decomposed.skew        // => {x: <int>, y: <int>, z: <int>}
         *     decomposed.scale       // => {x: <int>, y: <int>, z: <int>}
         * 
         */
        decompose: function(array) {
            var matrix = {
                m11: array[0],
                m12: array[1],
                m13: array[2],
                m14: array[3],
                m21: array[4],
                m22: array[5],
                m23: array[6],
                m24: array[7],
                m31: array[8],
                m32: array[9],
                m33: array[10],
                m34: array[11],
                m41: array[12],
                m42: array[13],
                m43: array[14],
                m44: array[15],
            };

            return decompose(matrix);
        }
    };

    return Transformations;
});