From f50a81e089108e70a2cfa20a2b3c8fc4168cf0a9 Mon Sep 17 00:00:00 2001 From: sapics Date: Sat, 20 Oct 2018 20:06:48 +0900 Subject: [PATCH] Minor code minifier We can minify some codes which relate matrix.decompose(), because matrix.decompose() must return non-null object --- src/basic/Matrix.js | 13 ++++++------- src/view/View.js | 18 ++++++------------ 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/basic/Matrix.js b/src/basic/Matrix.js index dfec668d..32d4d75c 100644 --- a/src/basic/Matrix.js +++ b/src/basic/Matrix.js @@ -672,12 +672,11 @@ var Matrix = Base.extend(/** @lends Matrix# */{ }, /** - * Attempts to decompose the affine transformation described by this matrix - * into `scaling`, `rotation` and `skewing`, and returns an object with - * these properties if it succeeded, `null` otherwise. + * Decomposes the affine transformation described by this matrix into + * `scaling`, `rotation` and `skewing`, and returns an object with + * these properties. * - * @return {Object} the decomposed matrix, or `null` if decomposition is not - * possible + * @return {Object} the decomposed matrix */ decompose: function() { // http://dev.w3.org/csswg/css3-2d-transforms/#matrix-decomposition @@ -795,7 +794,7 @@ var Matrix = Base.extend(/** @lends Matrix# */{ * @see #decompose() */ getScaling: function() { - return (this.decompose() || {}).scaling; + return this.decompose().scaling; }, /** @@ -806,7 +805,7 @@ var Matrix = Base.extend(/** @lends Matrix# */{ * @see #decompose() */ getRotation: function() { - return (this.decompose() || {}).rotation; + return this.decompose().rotation; }, /** diff --git a/src/view/View.js b/src/view/View.js index 99690f71..2e8a38b0 100644 --- a/src/view/View.js +++ b/src/view/View.js @@ -525,11 +525,9 @@ var View = Base.extend(Emitter, /** @lends View# */{ * @see #getScaling() */ getZoom: function() { - var decomposed = this._decompose(), - scaling = decomposed && decomposed.scaling; - // Use average since it can be non-uniform, and return 0 when it can't - // be decomposed. - return scaling ? (scaling.x + scaling.y) / 2 : 0; + var scaling = this._decompose().scaling; + // Use average since it can be non-uniform. + return (scaling.x + scaling.y) / 2; }, setZoom: function(zoom) { @@ -545,8 +543,7 @@ var View = Base.extend(Emitter, /** @lends View# */{ * @type Number */ getRotation: function() { - var decomposed = this._decompose(); - return decomposed && decomposed.rotation; + return this._decompose().rotation; }, setRotation: function(rotation) { @@ -565,11 +562,8 @@ var View = Base.extend(Emitter, /** @lends View# */{ * @see #getZoom() */ getScaling: function() { - var decomposed = this._decompose(), - scaling = decomposed && decomposed.scaling; - return scaling - ? new LinkedPoint(scaling.x, scaling.y, this, 'setScaling') - : undefined; + var scaling = this._decompose().scaling; + return new LinkedPoint(scaling.x, scaling.y, this, 'setScaling'); }, setScaling: function(/* scaling */) {