From 4ab541a53f890faefa22696e10704a87916ccbd7 Mon Sep 17 00:00:00 2001 From: dhrname Date: Fri, 20 Mar 2015 23:28:31 +0900 Subject: [PATCH] Support a 'spline' mode --- org/w3c/dom/smil.js | 13 ++++++++++++- tool/Spec/spec/SvgDomSpec.js | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/org/w3c/dom/smil.js b/org/w3c/dom/smil.js index dc74da7..cfe1c6d 100644 --- a/org/w3c/dom/smil.js +++ b/org/w3c/dom/smil.js @@ -557,7 +557,7 @@ base("$from").of( { keyTime: 1, /*keySpline属性の値を設定*/ - keySpline: null, + keySplines: null, /*全体の行列ノルム(距離)*/ norm: 1, @@ -586,6 +586,17 @@ base("$from").of( { this.keyTime = this.to.distance(this.to.from) / this.norm; return f; } else if (this.mode === "spline") { + var x = 0, + y = 0, + 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; + y = (y4-3*(y3+y2)-y1)*t*t*t + 3*(y3-2*y2+y1)*t*t + 3*(y2-y1)*t + y1; + return y+""; + }; + }, + tk = this.keySplines; + return bezier(0, 0, tk[0], tk[1], tk[2], tk[3], 1, 1); } else if (this.mode === "discrete") { return function (t) { return isNaN(t) ? this.string diff --git a/tool/Spec/spec/SvgDomSpec.js b/tool/Spec/spec/SvgDomSpec.js index 509e879..2f4a21c 100644 --- a/tool/Spec/spec/SvgDomSpec.js +++ b/tool/Spec/spec/SvgDomSpec.js @@ -3109,7 +3109,7 @@ describe("SMIL Animation Spec", function() { it("should be this for the value (limit value analysis)", function() { expect(calc.mode).toBe("linear"); expect(calc.keyTime).toEqual(1); - expect(calc.keySpline).toBeNull(); + expect(calc.keySplines).toBeNull(); expect(calc.call()(0)).toBe("0"); expect(calc.keyTime).toBe(1); @@ -3187,6 +3187,13 @@ describe("SMIL Animation Spec", function() { calc.to = base("$from").up(); calc.to.from = base("$from").up(); calc.mode = "discrete"; + calc.keyTime = 0.5; + calc.to.degit = 1; + calc.to.string = "0.5"; + expect(calc.call()(0.2)).toBe("0.5"); + expect(calc.call()(0.3)).toBe("0.5"); + /*もう一度確かめる*/ + expect(calc.call()(0.2)).toBe("0.5"); } ); /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/ it("should be this for the value (the invalid partion)", function() { @@ -3207,5 +3214,29 @@ describe("SMIL Animation Spec", function() { calc.mode = "discrete"; expect(calc.call()()).toEqual(calc.string); } ); + /*splineモードの境界条件を調べておく (limit value analysis)*/ + it("should be this for the value (spline mode limit value analysis)", function() { + /*3次ベジェ曲線の数式はこのページを参考にした http://geom.web.fc2.com/geometry/bezier/cubic.html*/ + var x = 0, + y = 0, + 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; + y = (y4-3*(y3+y2)-y1)*t*t*t + 3*(y3-2*y2+y1)*t*t + 3*(y2-y1)*t + y1; + return y; + }; + }; + expect(calc.keySplines).toBeNull(); + calc.mode = "spline"; + calc.keySplines = [0, 0, 1, 1]; + expect(calc.call()(0)).toBe(bezier(0,0, 0,0, 1,1, 1,1)(0)+""); + expect(calc.call()(1)).toBe(bezier(0,0, 0,0, 1,1, 1,1)(1)+""); + } ); + /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/ + it("should be this for the value (the valid partion on a spline mode )", function() { + } ); + /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/ + it("should be this for the value (the invalid partion on a spline mode )", function() { + } ); } ); } ); -- 2.11.0