diff options
author | wout <wout@impinc.co.uk> | 2014-07-12 14:06:49 +0200 |
---|---|---|
committer | wout <wout@impinc.co.uk> | 2014-07-12 14:06:49 +0200 |
commit | 501cb5387007a89af382717376c773a1ec6b68ae (patch) | |
tree | 8edcd6d28407c02430a3ace7245384bc894eb867 /src | |
parent | 462d2cd3738c904db0be7086878d1fcc17b79553 (diff) | |
download | svg.js-501cb5387007a89af382717376c773a1ec6b68ae.tar.gz svg.js-501cb5387007a89af382717376c773a1ec6b68ae.zip |
Further debugging matrix new implementation
Diffstat (limited to 'src')
-rwxr-xr-x | src/element.js | 4 | ||||
-rwxr-xr-x | src/ellipse.js | 4 | ||||
-rw-r--r-- | src/helpers.js | 2 | ||||
-rw-r--r-- | src/matrix.js | 18 | ||||
-rw-r--r-- | src/transform.js | 6 |
5 files changed, 18 insertions, 16 deletions
diff --git a/src/element.js b/src/element.js index 6310b6b..59e713f 100755 --- a/src/element.js +++ b/src/element.js @@ -21,7 +21,7 @@ SVG.Element = SVG.invent({ x: function(x) { if (x != null) { x = new SVG.Number(x) - x.value /= this.ctm().extract().scaleX + x.value /= this.transform('scaleX') } return this.attr('x', x) } @@ -29,7 +29,7 @@ SVG.Element = SVG.invent({ , y: function(y) { if (y != null) { y = new SVG.Number(y) - y.value /= this.ctm().extract().scaleY + y.value /= this.transform('scaleY') } return this.attr('y', y) } diff --git a/src/ellipse.js b/src/ellipse.js index f4ab6c9..d64209a 100755 --- a/src/ellipse.js +++ b/src/ellipse.js @@ -64,11 +64,11 @@ SVG.extend(SVG.Circle, SVG.Ellipse, { } // Move by center over x-axis , cx: function(x) { - return x == null ? this.attr('cx') : this.attr('cx', new SVG.Number(x).divide(this.ctm().scaleX)) + return x == null ? this.attr('cx') : this.attr('cx', new SVG.Number(x).divide(this.transform('scaleX'))) } // Move by center over y-axis , cy: function(y) { - return y == null ? this.attr('cy') : this.attr('cy', new SVG.Number(y).divide(this.ctm().scaleY)) + return y == null ? this.attr('cy') : this.attr('cy', new SVG.Number(y).divide(this.transform('scaleY'))) } // Set width of element , width: function(width) { diff --git a/src/helpers.js b/src/helpers.js index 11f5017..b22a559 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -51,7 +51,7 @@ function deltaTransformPoint(matrix, point) { // Map matrix array to object function arrayToMatrix(a) { - return { a: a[0], b: a[1], c: a[2], e: a[3], f: a[4], g: a[5] } + return { a: a[0], b: a[1], c: a[2], d: a[3], e: a[4], f: a[5] } } // Calculate position according to from and to diff --git a/src/matrix.js b/src/matrix.js index fb61bf0..b6c839d 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -25,21 +25,22 @@ SVG.Matrix = SVG.invent({ // Extract individual transformations extract: function() { // Find transform points - var px = deltaTransformPoint(this, { x: 0, y: 1 }) - , py = deltaTransformPoint(this, { x: 1, y: 0 }) + var px = deltaTransformPoint(this, { x: 0, y: 1 }) + , py = deltaTransformPoint(this, { x: 1, y: 0 }) + , skewX = 180 / Math.PI * Math.atan2(px.y, px.x) - 90 return { // Translation x: this.e , y: this.f // Skew - , skewX: 180 / Math.PI * Math.atan2(px.y, px.x) - 90 + , skewX: skewX , skewY: 180 / Math.PI * Math.atan2(py.y, py.x) // Scale , scaleX: Math.sqrt(this.a * this.a + this.b * this.b) , scaleY: Math.sqrt(this.c * this.c + this.d * this.d) // Rotation - , rotation: this.skewX + , rotation: skewX } } // Multiply @@ -63,15 +64,12 @@ SVG.Matrix = SVG.invent({ } // Rotate , rotate: function(d, x, y) { - // Fall back to native rotate method - if (x == null) return new SVG.Matrix(this.native().rotate(d)) - // Convert degrees to radians d = SVG.utils.radians(d) - + return new SVG.Matrix(1, 0, 0, 1, x, y) - //.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(Math.cos(d), Math.sin(d), -Math.sin(d), Math.cos(d), 0, 0)) + .multiply(new SVG.Matrix(1, 0, 0, 1, -x, -y)) } // Flip , flip: function(a) { diff --git a/src/transform.js b/src/transform.js index c78865d..ba4cdb9 100644 --- a/src/transform.js +++ b/src/transform.js @@ -5,6 +5,10 @@ SVG.extend(SVG.Element, { if (o == null) return this.ctm().extract() + // Singular getter + else if (typeof o === 'string') + return this.ctm().extract()[o] + // Get current matrix var matrix = new SVG.Matrix(this) @@ -36,7 +40,7 @@ SVG.extend(SVG.Element, { // Act on translate else if (o.x || o.y) matrix = matrix.translate(o.x, o.y) -console.log(o, matrix) + return this.attr('transform', matrix) } // Reset all transformations |