/* * Add some helpers for matrices. This is ported from SkMatrix.cpp and others * to save complexity and overhead of going back and forth between C++ and JS layers. * I would have liked to use something like DOMMatrix, except it * isn't widely supported (would need polyfills) and it doesn't * have a mapPoints() function (which could maybe be tacked on here). * If DOMMatrix catches on, it would be worth re-considering this usage. */ CanvasKit.Matrix = {}; function sdot() { // to be called with an even number of scalar args var acc = 0; for (var i=0; i < arguments.length-1; i+=2) { acc += arguments[i] * arguments[i+1]; } return acc; } // Private general matrix functions used in both 3x3s and 4x4s. // Return a square identity matrix of size n. var identityN = function(n) { var size = n*n; var m = new Array(size); while(size--) { m[size] = size%(n+1) === 0 ? 1.0 : 0.0; } return m; }; // Stride, a function for compactly representing several ways of copying an array into another. // Write vector `v` into matrix `m`. `m` is a matrix encoded as an array in row-major // order. Its width is passed as `width`. `v` is an array with length < (m.length/width). // An element of `v` is copied into `m` starting at `offset` and moving `colStride` cols right // each row. // // For example, a width of 4, offset of 3, and stride of -1 would put the vector here. // _ _ 0 _ // _ 1 _ _ // 2 _ _ _ // _ _ _ 3 // var stride = function(v, m, width, offset, colStride) { for (var i=0; i