refactor Matrix2D, return early when appending identity

This commit is contained in:
Mikael Sand
2019-07-19 00:33:48 +03:00
parent 0e7acd846f
commit d054af815e
+10 -3
View File
@@ -63,6 +63,11 @@ export function toArray() {
* @param {Number} ty2
**/
export function append(a2, b2, c2, d2, tx2, ty2) {
const change = a2 !== 1 || b2 !== 0 || c2 !== 0 || d2 !== 1;
const translate = tx2 !== 0 || ty2 !== 0;
if (!change && !translate) {
return;
}
if (hasInitialState) {
hasInitialState = false;
a = a2;
@@ -77,14 +82,16 @@ export function append(a2, b2, c2, d2, tx2, ty2) {
const b1 = b;
const c1 = c;
const d1 = d;
if (a2 !== 1 || b2 !== 0 || c2 !== 0 || d2 !== 1) {
if (change) {
a = a1 * a2 + c1 * b2;
b = b1 * a2 + d1 * b2;
c = a1 * c2 + c1 * d2;
d = b1 * c2 + d1 * d2;
}
tx = a1 * tx2 + c1 * ty2 + tx;
ty = b1 * tx2 + d1 * ty2 + ty;
if (translate) {
tx = a1 * tx2 + c1 * ty2 + tx;
ty = b1 * tx2 + d1 * ty2 + ty;
}
}
/**