diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-06-28 22:58:51 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-06-28 22:58:51 +0200 |
commit | 4009da2e223e197a98bb79afd68c0a6753e0c37e (patch) | |
tree | 7d8353b07ef289c0e6b7f14d742c1af49df816ec /src | |
parent | 739e2dff566204a601113d64d7e47a39a41b306b (diff) | |
download | svg.js-4009da2e223e197a98bb79afd68c0a6753e0c37e.tar.gz svg.js-4009da2e223e197a98bb79afd68c0a6753e0c37e.zip |
fix origin bug
Diffstat (limited to 'src')
-rw-r--r-- | src/matrix.js | 26 | ||||
-rw-r--r-- | src/morph.js | 9 | ||||
-rw-r--r-- | src/runner.js | 20 |
3 files changed, 22 insertions, 33 deletions
diff --git a/src/matrix.js b/src/matrix.js index 25d686a..31d3d58 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -103,14 +103,14 @@ SVG.Matrix = SVG.invent({ }, // Decomposes this matrix into its affine parameters - decompose: function (ox=0, oy=0) { + decompose: function (cx=0, cy=0) { // Get the parameters from the matrix var a = this.a var b = this.b var c = this.c var d = this.d - var e = this.e - ox - var f = this.f - oy + var e = this.e + var f = this.f // Figure out if the winding direction is clockwise or counterclockwise var determinant = a * d - b * c @@ -119,13 +119,19 @@ SVG.Matrix = SVG.invent({ // Since we only shear in x, we can use the x basis to get the x scale // and the rotation of the resulting matrix var sx = ccw * Math.sqrt(a * a + b * b) - var theta = 180 / Math.PI * Math.atan2(ccw * b, ccw * a) + var thetaRad = Math.atan2(ccw * b, ccw * a) + var theta = 180 / Math.PI * thetaRad + var ct = Math.cos(thetaRad) + var st = Math.sin(thetaRad) // We can then solve the y basis vector simultaneously to get the other // two affine parameters directly from these parameters var lam = (a * c + b * d) / determinant var sy = ((c * sx) / (lam * a - b)) || ((d * sx) / (lam * b + a)) + let tx = e - cx + cx * ct * sx + cy * (lam * ct * sx - st * sy) + let ty = f - cy + cx * st * sx + cy * (lam * st * sx + ct * sy) + // Construct the decomposition and return it return { // Return the affine parameters @@ -133,18 +139,18 @@ SVG.Matrix = SVG.invent({ scaleY: sy, shear: lam, rotate: theta, - translateX: e + ox, - translateY: f + oy, - originX: ox, - originY: oy, + translateX: tx, + translateY: ty, + originX: cx, + originY: cy, // Return the matrix parameters a: this.a, b: this.b, c: this.c, d: this.d, - e: this.e + ox, - f: this.f + oy + e: this.e, + f: this.f } }, diff --git a/src/morph.js b/src/morph.js index 67d14f7..022c51e 100644 --- a/src/morph.js +++ b/src/morph.js @@ -161,17 +161,12 @@ SVG.Morphable.TransformBag = SVG.invent({ SVG.Matrix.call(this, obj) if (obj && obj.origin) { - obj.originX = origin[0] - obj.originY = origin[1] + obj.originX = obj.origin[0] + obj.originY = obj.origin[1] } this.originX = obj && obj.originX || 0 this.originY = obj && obj.originY || 0 - - /*if (obj && obj.origin){ - this.translateO(-obj.origin[0], -obj.origin[1]) - }*/ - //this.value = new SVG.Matrix(obj) }, extend: { diff --git a/src/runner.js b/src/runner.js index 6094aaf..963f31b 100644 --- a/src/runner.js +++ b/src/runner.js @@ -673,21 +673,17 @@ SVG.extend(SVG.Runner, { morpher = new SVG.Morphable().type(morphType) morpher.stepper(this._stepper) - //morpher.to(transforms) + morpher.to(transforms) this.queue(function() { let element = this.element() element.addRunner(this) - if (!origin/* && affine*/) { + if (!origin && affine) { origin = getOrigin(transforms, element) transforms.origin = origin - console.log('Affine Parameters:', transforms) - morpher.to(transforms) - - console.log('End parameters:', morpher.to()) } if (!relative && !this._isDeclarative) { @@ -699,25 +695,17 @@ SVG.extend(SVG.Runner, { let startMatrix = new SVG.Matrix(relative ? undefined : element) // make sure to add an origin if we morph affine - //if (affine) { - /*startMatrix = startMatrix.decompose(origin[0], origin[1]) - - startMatrix = new SVG.Matrix().compose(startMatrix)*/ - + if (affine) { startMatrix.origin = origin - //} + } // FIXME: correct the rotation so that it takes the shortest path morpher.from(startMatrix) - - console.log('Start Parameters:', morpher.from()) - }, function (pos) { if (!relative) this.clearTransform() var matrix = morpher.at(pos) - // matrix = matrix.translate(origin[0], origin[1]) this.addTransform(matrix) return morpher.done() |