48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
"use strict";
|
|
class TransformMatrix {
|
|
constructor() {
|
|
this.reset();
|
|
}
|
|
reset() {
|
|
this.a = 1;
|
|
this.b = 0;
|
|
this.c = 0;
|
|
this.d = 1;
|
|
this.tx = 0;
|
|
this.ty = 0;
|
|
this.stack = [];
|
|
}
|
|
translate(dx, dy) {
|
|
this.tx += this.a * dx + this.c * dy;
|
|
this.ty += this.b * dx + this.d * dy;
|
|
}
|
|
scale(sx, sy, cx = 0, cy = 0) {
|
|
this.translate(cx, cy);
|
|
this.a *= sx;
|
|
this.b *= sx;
|
|
this.c *= sy;
|
|
this.d *= sy;
|
|
this.translate(-cx, -cy);
|
|
}
|
|
toArray() {
|
|
return [this.a, this.b, this.c, this.d, this.tx, this.ty];
|
|
}
|
|
// 用于调试的字符串表示
|
|
toString() {
|
|
return `[${this.a.toFixed(2)}, ${this.b.toFixed(2)}, ${this.c.toFixed(2)}, ${this.d.toFixed(2)}, ${this.tx.toFixed(1)}, ${this.ty.toFixed(1)}]`;
|
|
}
|
|
// 克隆方法
|
|
clone() {
|
|
const clone = new TransformMatrix();
|
|
clone.a = this.a;
|
|
clone.b = this.b;
|
|
clone.c = this.c;
|
|
clone.d = this.d;
|
|
clone.tx = this.tx;
|
|
clone.ty = this.ty;
|
|
return clone;
|
|
}
|
|
}
|
|
exports.TransformMatrix = TransformMatrix;
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/index/transform-matrix.js.map
|