From 064d632d65e9c5a1ae43f5a6648c8163e172b5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sun, 8 Dec 2013 22:12:36 +0100 Subject: [PATCH] More matrix related clean-ups. --- src/basic/Matrix.js | 4 ++++ src/item/Item.js | 7 +++---- src/path/PathItem.js | 8 ++------ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/basic/Matrix.js b/src/basic/Matrix.js index c498e566..dce19957 100644 --- a/src/basic/Matrix.js +++ b/src/basic/Matrix.js @@ -373,6 +373,10 @@ var Matrix = Base.extend(/** @lends Matrix# */{ && this._tx === 0 && this._ty === 0; }, + orNullIfIdentity: function() { + return this.isIdentity() ? null : this; + }, + /** * Returns whether the transform is invertible. A transform is not * invertible if the determinant is 0 or any value is non-finite or NaN. diff --git a/src/item/Item.js b/src/item/Item.js index de1ab380..41bb6a7f 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -829,7 +829,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{ // See if we can cache these bounds. We only cache the bounds // transformed with the internally stored _matrix, (the default if no // matrix is passed). - var _matrix = this._matrix, + matrix = matrix && matrix.orNullIfIdentity(); + var _matrix = this._matrix.orNullIfIdentity(), cache = (!matrix || matrix.equals(_matrix)) && getter; // Set up a boundsCache structure that keeps track of items that keep // cached bounds that depend on this item. We store this in our parent, @@ -862,9 +863,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{ // If the result of concatinating the passed matrix with our internal // one is an identity transformation, set it to null for faster // processing - if (_matrix.isIdentity()) - _matrix = null; - matrix = !matrix || matrix.isIdentity() + matrix = !matrix ? _matrix : _matrix ? matrix.clone().concatenate(_matrix) diff --git a/src/path/PathItem.js b/src/path/PathItem.js index 980ad3e9..df19d109 100644 --- a/src/path/PathItem.js +++ b/src/path/PathItem.js @@ -67,14 +67,10 @@ var PathItem = Item.extend(/** @lends PathItem# */{ var locations = [], curves1 = this.getCurves(), curves2 = path.getCurves(), - matrix1 = this._matrix, - matrix2 = path._matrix, + matrix1 = this._matrix.orNullIfIdentity(), + matrix2 = path._matrix.orNullIfIdentity(), length2 = curves2.length, values2 = []; - if (matrix1.isIdentity()) - matrix1 = null; - if (matrix2.isIdentity()) - matrix2 = null; for (var i = 0; i < length2; i++) values2[i] = curves2[i].getValues(matrix2); for (var i = 0, l = curves1.length; i < l; i++) {