UNPKG

@bitblit/ratchet-common

Version:

Common tools for general use

77 lines 1.94 kB
export class MatrixFactory { constructor() { } static multiply(tx) { let rval = MatrixFactory.identity(); tx.forEach(t => { rval = { a: (rval.a * t.a) + (rval.b * t.c) + ((rval.u | 0) * 0), b: (rval.a * t.b) + (rval.b * t.d) + ((rval.u | 0) * 0), u: (rval.a * (t.u | 0)) + (rval.b * (t.v | 0)) + ((rval.u | 0) * 1), c: (rval.c * t.a) + (rval.d * t.c) + ((rval.v | 0) * 0), d: (rval.c * t.b) + (rval.d * t.d) + ((rval.v | 0) * 0), v: (rval.c * (t.u | 0)) + (rval.d * (t.v | 0)) + ((rval.v | 0) * 1), }; }); return rval; } static translate(xMove, yMove) { const rval = MatrixFactory.identity(); rval.u = xMove; rval.v = yMove; return rval; } static scaleUniform(scale) { return MatrixFactory.scale(scale, scale); } static scale(xScale, yScale) { return { a: xScale, b: 0, c: 0, d: yScale, }; } static rotate(angleTheta) { return { a: Math.cos(angleTheta), b: -1 * Math.sin(angleTheta), c: Math.sin(angleTheta), d: Math.cos(angleTheta) }; } static shear(xShear, yShear) { return { a: 1, b: xShear, c: yShear, d: 1 }; } static mirrorAboutYAxis() { return { a: -1, b: 0, c: 0, d: 1 }; } static mirrorAboutXAxis() { return { a: 1, b: 0, c: 0, d: -1 }; } static identity() { return { a: 1, b: 0, c: 0, d: 1, u: 0, v: 0 }; } } //# sourceMappingURL=matrix-factory.js.map