From: dhrname Date: Sat, 28 Mar 2015 14:16:10 +0000 (+0900) Subject: Support a spline mode X-Git-Tag: version22~261 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=ef73534978adb8b7b0aad07b7c4c1e6913caa4ba;p=sie%2Fsie.git Support a spline mode --- diff --git a/org/w3c/dom/smil.js b/org/w3c/dom/smil.js index da5c2f5..aa38a21 100644 --- a/org/w3c/dom/smil.js +++ b/org/w3c/dom/smil.js @@ -591,9 +591,23 @@ base("$from").of( { y = 0, that = this, bezier = function (x1, y1, x2, y2, x3, y3, x4, y4) { - return function (t) { - x = (x4-3*(x3-x2)-x1)*t*t*t + 3*(x3-2*x2+x1)*t*t + 3*(x2-x1)*t + x1; + return function (x) { + var a = [x4-3*(x3-x2)-x1, 3*(x3-2*x2+x1), 3*(x2-x1), x1-x]; + /*三次方程式の解から、ベジェ曲線のyを求める*/ + var s = Math.carda(a), + i = 0, + si, + t = 0; + while (s[i]) { + si = s[i]; + if ((si.i === 0) && (si.r <= 1) && (si.r >= 0)) { + t = si.r; + } + ++i; + } + console.log(t); y = (y4-3*(y3-y2)-y1)*t*t*t + 3*(y3-2*y2+y1)*t*t + 3*(y2-y1)*t + y1; + console.log(s, y); return f(y); }; }, @@ -650,7 +664,7 @@ Math.carda = function (a) { /*共役複素数*/ x.push( { r: x[x.length-1].r, - i: - x[x.length].i + i: - x[x.length-1].i } ); return x; } else { diff --git a/tool/Spec/spec/SvgDomSpec.js b/tool/Spec/spec/SvgDomSpec.js index 761576f..18671f6 100644 --- a/tool/Spec/spec/SvgDomSpec.js +++ b/tool/Spec/spec/SvgDomSpec.js @@ -3261,13 +3261,13 @@ describe("SMIL Animation Spec", function() { calc.to.from = from; expect(calc.call()(1)).toBe(b(1).y+".0"); calc.to.from = from; - expect(calc.call()(0.5)).toBe(b(0.5).y.toFixed(1)); + expect(calc.call()( b(0.5).x )).toBe(b(0.5).y.toFixed(1)); var ff = function(k) { calc.keySplines = k; calc.to.degit = 10; var b = bezier(0,0, k[0],k[1], k[2],k[3], 1,1), - epsiron = 0.00001; //誤差 + epsiron = 1e-10; //誤差 expect(calc.call()(0)).toBe(b(0).y.toFixed(10)); calc.to.from = from; expect(calc.call()(1)).toBe(b(1).y.toFixed(10));