-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransform-stack.ts
36 lines (27 loc) · 910 Bytes
/
transform-stack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Matrix } from "./matrix";
export class TransformStack {
private _transforms: Matrix[] = [];
private _currentTransform: Matrix = Matrix.identity();
public save(): void {
this._transforms.push(this._currentTransform);
this._currentTransform = this._currentTransform.clone();
}
public restore(): void {
this._currentTransform = this._transforms.pop();
}
public translate(x: number, y: number): Matrix {
return this._currentTransform.translate(x, y);
}
public rotate(angle: number): Matrix {
return this._currentTransform.rotate(angle);
}
public scale(x: number, y: number): Matrix {
return this._currentTransform.scale(x, y);
}
public set current(matrix: Matrix) {
this._currentTransform = matrix;
}
public get current(): Matrix {
return this._currentTransform;
}
}