From: Ulrich-Matthias Schäfer Date: Wed, 4 Jul 2018 16:27:00 +0000 (+0200) Subject: make TransformBag clone the object before altering X-Git-Tag: 3.0.0~60^2~21 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ee25f92f87f2fc5bb6ab65023c4515a285535ff4;p=svg.js.git make TransformBag clone the object before altering --- diff --git a/dirty.html b/dirty.html index 896449b..df7c871 100644 --- a/dirty.html +++ b/dirty.html @@ -275,12 +275,15 @@ let obj = { rotate: 180, origin: 'center', translate: [300, 0] } let obj2 = { rotate: 360, origin: 'center' } a.clone() // startPosition -a.clone().transform(obj, true).transform(obj2, true) // endPosition +//a.clone().transform(obj, true).transform(obj2, true) // endPosition // that works a.animate(new SVG.Spring(50, 30)).transform(obj) // animation // that breaks (why??) -// a.clone().animate(new SVG.Spring(50, 30)).transform(obj) // animation + +var b = a.clone().animate(new SVG.Spring(500, 30)) +//debugger +b.transform(obj) // animation //a.animate(300).transform(obj, true).transform(obj2, true) // animation diff --git a/src/controller.js b/src/controller.js index c2a9355..46c1771 100644 --- a/src/controller.js +++ b/src/controller.js @@ -124,6 +124,9 @@ SVG.Spring = SVG.invent ({ c.done = dt == Infinity if(dt == Infinity) return target if(dt == 0) return current + + if (dt > 100) dt = 16 + dt /= 1000 // Get the previous velocity diff --git a/src/morph.js b/src/morph.js index ff902ae..18ed6b5 100644 --- a/src/morph.js +++ b/src/morph.js @@ -158,15 +158,22 @@ SVG.Morphable.TransformBag = SVG.invent({ } } - SVG.Matrix.call(this, obj) + var data = {...(obj || {})} - if (obj && obj.origin) { - obj.originX = obj.origin[0] - obj.originY = obj.origin[1] + if (typeof data.origin == 'string') { + delete data.origin } - this.originX = obj && obj.originX || 0 - this.originY = obj && obj.originY || 0 + SVG.Matrix.call(this, data) + + + if (data.origin) { + data.originX = data.origin[0] + data.originY = data.origin[1] + } + + this.originX = data.originX || 0 + this.originY = data.originY || 0 }, extend: {