diff --git a/lib/Matrix2D.js b/lib/Matrix2D.js index 495ae008..4721ed7b 100644 --- a/lib/Matrix2D.js +++ b/lib/Matrix2D.js @@ -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; + } } /**