Commit f76f34d4 authored by rockyl's avatar rockyl

增加解码方法

parent f7ff466e
import {Point} from "././Point";
import {HashObject} from "../HashObject";
import {cos, DEG_TO_RAD, RAD_TO_DEG, sin} from "../const";
import {cos, DEG_TO_RAD, PI_2, RAD_TO_DEG, sin} from "../const";
import Transform from "./Transform";
/**
* 2维矩阵
......@@ -421,6 +422,42 @@ export class Matrix extends HashObject {
return Math.round(Math.atan2(this.b, this.a) * RAD_TO_DEG);
}
decompose(transform: Transform) {
const a = this.a;
const b = this.b;
const c = this.c;
const d = this.d;
//取斜切
const skewX = -Math.atan2(-c, d);
const skewY = Math.atan2(b, a);
const delta = Math.abs(skewX + skewY);
//斜切值和旋转不唯一,所以设定条件只取其一
if (delta < 0.00001 || Math.abs(PI_2 - delta) < 0.00001) {
transform.rotation = skewY;
//考虑是否必要
if (a < 0 && d >= 0) {
transform.rotation += (transform.rotation <= 0) ? Math.PI : -Math.PI;
}
transform.skew.x = transform.skew.y = 0;
}
else {
transform.rotation = 0;
transform.skew.x = skewX;
transform.skew.y = skewY;
}
//取缩放
transform.scale.x = Math.sqrt((a * a) + (b * b));
transform.scale.y = Math.sqrt((c * c) + (d * d));
//取位置
transform.position.x = this.tx;
transform.position.y = this.ty;
return transform;
}
/**
* Creates an array from the current Matrix object.与glsl中的mat3对应,注意行列主序执行transpose;
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment