From 7164e5617d7413b4c7806466457d7f08c1fd3220 Mon Sep 17 00:00:00 2001 From: Rémi Tétreault Date: Wed, 2 Nov 2016 18:25:35 -0400 Subject: Fix the implementation of the skew transform Also fix a bug where when calling scale with 3 parameters, cx was not set with the right value. --- src/matrix.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/matrix.js b/src/matrix.js index 37bd860..bcf39e4 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -113,12 +113,13 @@ SVG.Matrix = SVG.invent({ } // Scale matrix , scale: function(x, y, cx, cy) { - // support universal scale - if (arguments.length == 1 || arguments.length == 3) + // support uniformal scale + if (arguments.length == 1) { y = x - if (arguments.length == 3) { + } else if (arguments.length == 3) { cy = cx cx = y + y = x } return this.around(cx, cy, new SVG.Matrix(x, 0, 0, y, 0, 0)) @@ -136,15 +137,28 @@ SVG.Matrix = SVG.invent({ } // Skew , skew: function(x, y, cx, cy) { - return this.around(cx, cy, this.native().skewX(x || 0).skewY(y || 0)) + // support uniformal skew + if (arguments.length == 1) { + y = x + } else if (arguments.length == 3) { + cy = cx + cx = y + y = x + } + + // convert degrees to radians + x = SVG.utils.radians(x) + y = SVG.utils.radians(y) + + return this.around(cx, cy, new SVG.Matrix(1, Math.tan(y), Math.tan(x), 1, 0, 0)) } // SkewX , skewX: function(x, cx, cy) { - return this.around(cx, cy, this.native().skewX(x || 0)) + return this.skew(x, 0, cx, cy) } // SkewY , skewY: function(y, cx, cy) { - return this.around(cx, cy, this.native().skewY(y || 0)) + return this.skew(0, y, cx, cy) } // Transform around a center point , around: function(cx, cy, matrix) { -- cgit v1.2.3