diff options
author | wout <wout@impinc.co.uk> | 2014-07-12 21:18:26 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-07-12 21:18:26 +0200 |
commit | 40bf2f8ecda3f426e7f13e1d891ab1ab6e004116 (patch) | |
tree | b3d339c104c2c0e829fd5e607428a9e077619e12 /src/matrix.js | |
parent | 03f358a4d85a292c16774ba64836e0b2937df2fe (diff) | |
download | svg.js-40bf2f8ecda3f426e7f13e1d891ab1ab6e004116.tar.gz svg.js-40bf2f8ecda3f426e7f13e1d891ab1ab6e004116.zip |
Added support for scale center on matrices
Diffstat (limited to 'src/matrix.js')
-rw-r--r-- | src/matrix.js | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/matrix.js b/src/matrix.js index 314e1e0..e2afbef 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -57,26 +57,36 @@ SVG.Matrix = SVG.invent({ } // Scale , scale: function(x, y, cx, cy) { - if (y == null) - return new SVG.Matrix(this.native().scale(x)) - else - return new SVG.Matrix(this.native().scaleNonUniform(x, y)) + // Support universal scale + if (arguments.length == 1 || arguments.length == 3) + y = x + if (arguments.length == 3) { + cy = cx + cx = y + } + + return this + .multiply(new SVG.Matrix(1, 0, 0, 1, cx || 0, cy || 0)) + .multiply(new SVG.Matrix(x, 0, 0, y, 0, 0)) + .multiply(new SVG.Matrix(1, 0, 0, 1, -cx || 0, -cy || 0)) } // Rotate - , rotate: function(d, x, y) { + , rotate: function(d, cx, cy) { // Convert degrees to radians d = SVG.utils.radians(d) - return new SVG.Matrix(1, 0, 0, 1, x, y) + return this + .multiply(new SVG.Matrix(1, 0, 0, 1, cx || 0, cy || 0)) .multiply(new SVG.Matrix(Math.cos(d), Math.sin(d), -Math.sin(d), Math.cos(d), 0, 0)) - .multiply(new SVG.Matrix(1, 0, 0, 1, -x, -y)) + .multiply(new SVG.Matrix(1, 0, 0, 1, -cx || 0, -cy || 0)) } // Flip , flip: function(a) { return new SVG.Matrix(this.native()['flip' + a.toUpperCase()]()) } // Skew - , skew: function(x, y) { + , skew: function(x, y, cx, cy) { + // IMPLEMENT SKEW CENTER POINT return new SVG.Matrix(this.native().skewX(x || 0).skewY(y || 0)) } // Convert this to SVGMatrix |