From: Saivan Date: Thu, 28 Jun 2018 23:18:54 +0000 (+1000) Subject: Added a potential fix for the problem X-Git-Tag: 3.0.0~60^2~26 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9e7d902339755b37ba228f837700c3886a337aa2;p=svg.js.git Added a potential fix for the problem --- diff --git a/dirty.html b/dirty.html index 3eadb0e..5e6e6e1 100644 --- a/dirty.html +++ b/dirty.html @@ -218,11 +218,11 @@ a.timeline().source(() => { }) -let obj = { rotate: 90, shear:2, origin: [600, 600], translate: [100, 100] } +let obj = { rotate: 100, shear:2, origin: [600, 600], translate: [100, 100] } a.clone() // startPosition a.clone().transform(obj) // endPosition -a.animate(new SVG.PID(0.1, 0.1)).transform(obj) // animation +a.animate(new SVG.Spring(50, 30)).transform(obj) // animation // Put an ellipse where we expect the object to be diff --git a/src/matrix.js b/src/matrix.js index 05e9c7d..4396816 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -129,6 +129,7 @@ SVG.Matrix = SVG.invent({ var lam = (a * c + b * d) / determinant var sy = ((c * sx) / (lam * a - b)) || ((d * sx) / (lam * b + a)) + // Use the translations 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) diff --git a/src/runner.js b/src/runner.js index 963f31b..4c9dda2 100644 --- a/src/runner.js +++ b/src/runner.js @@ -700,6 +700,13 @@ SVG.extend(SVG.Runner, { } // FIXME: correct the rotation so that it takes the shortest path + // GIVE ME (rCurrent) (rTarget) - to store the current/target angle + const possibilities = [rTarget - 360, rTarget, rTarget + 360] + const distances = possibilities.map( a => Math.abs(a - rCurrent) ) + const shortest = Math.min(...distances) + const index = distances.indexOf(shortest) + const target = possibilities[index] + morpher.from(startMatrix) }, function (pos) {