| 74 | * 3x3 with 9 configurable values. |
| 75 | */ |
| 76 | export class Matrix implements ISerializable { |
| 77 | private _data:Array<number>; |
| 78 | |
| 79 | constructor(a:number = 1, b:number = 0, c:number = 0, d:number = 1, tx:number = 0, ty:number = 0) { |
| 80 | this._data = [a, c, tx, b, d, ty, 0, 0, 1]; |
| 81 | } |
| 82 | |
| 83 | private dotProduct(o:Array<number>):Array<number> { |
| 84 | if (o.length < 9) { |
| 85 | throw new Error('Matrix dot product expects a 3x3 Matrix'); |
| 86 | } |
| 87 | var res:Array<number> = [0, 0, 0, 0, 0, 0, 0, 0, 0]; |
| 88 | for (var i = 0; i < 3; i++) { |
| 89 | for (var j = 0; j < 3; j++) { |
| 90 | for (var k = 0; k < 3; k++) { |
| 91 | res[i * 3 + j] += this._data[i * 3 + k] * o[k * 3 + j]; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | return res; |
| 96 | } |
| 97 | |
| 98 | public setTo(a:number = 1, b:number = 0, c:number = 0, d:number = 1, tx:number = 0, ty:number = 0):void { |
| 99 | this._data = [a, c, tx, b, d, ty, 0, 0, 1]; |
| 100 | } |
| 101 | |
| 102 | public translate(tX:number, tY:number):void { |
| 103 | this._data[2] += tX; |
| 104 | this._data[5] += tY; |
| 105 | } |
| 106 | |
| 107 | public rotate(q:number):void { |
| 108 | this._data = this.dotProduct([ |
| 109 | Math.cos(q), -Math.sin(q), 0, |
| 110 | Math.sin(q), Math.cos(q), 0, |
| 111 | 0, 0, 1 |
| 112 | ]); |
| 113 | } |
| 114 | |
| 115 | public scale(sx:number, sy:number):void { |
| 116 | this._data = this.dotProduct([ |
| 117 | sx, 0, 0, |
| 118 | 0, sy, 0, |
| 119 | 0, 0, 1 |
| 120 | ]); |
| 121 | } |
| 122 | |
| 123 | public identity():void { |
| 124 | this.setTo(1, 0, 0, 1, 0, 0); |
| 125 | } |
| 126 | |
| 127 | public createGradientBox(width:number, height:number, rotation:number, tX:number, tY:number):void { |
| 128 | this.createBox(width, height, rotation, tX, tY); |
| 129 | } |
| 130 | |
| 131 | public createBox(sX:number, sY:number, q:number, tX:number, tY:number):void { |
| 132 | this.identity(); |
| 133 | this.rotate(q); |
nothing calls this directly
no outgoing calls
no test coverage detected