From b3d89f778fe0f792f3125465c086a31daf8e65a3 Mon Sep 17 00:00:00 2001 From: dhrname Date: Sun, 22 Mar 2015 22:50:44 +0900 Subject: [PATCH] Modify the Spec for a 'spleine' mode --- org/w3c/dom/smil.js | 22 ++++++++++++---------- tool/Spec/spec/SvgDomSpec.js | 29 +++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/org/w3c/dom/smil.js b/org/w3c/dom/smil.js index cfe1c6d..9dcb6dc 100644 --- a/org/w3c/dom/smil.js +++ b/org/w3c/dom/smil.js @@ -586,16 +586,18 @@ 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; + this.to.call(); + var x = 0, + 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; + y = (y4-3*(y3+y2)-y1)*t*t*t + 3*(y3-2*y2+y1)*t*t + 3*(y2-y1)*t + y1; + return f(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) { diff --git a/tool/Spec/spec/SvgDomSpec.js b/tool/Spec/spec/SvgDomSpec.js index 2f4a21c..40c6aa3 100644 --- a/tool/Spec/spec/SvgDomSpec.js +++ b/tool/Spec/spec/SvgDomSpec.js @@ -3214,6 +3214,7 @@ 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*/ @@ -3228,12 +3229,36 @@ describe("SMIL Animation Spec", function() { }; expect(calc.keySplines).toBeNull(); calc.mode = "spline"; + expect( function() { + calc.call(); + }).toThrow(); 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)+""); + calc.to.degit = 1; + calc.to.from = from; + expect(calc.call()(0)).toBe(bezier(0,0, 0,0, 1,1, 1,1)(0)+".0"); + calc.to.from = from; + expect(calc.call()(1)).toBe(bezier(0,0, 0,0, 1,1, 1,1)(1)+".0"); + calc.to.from = from; + expect(calc.call()(0.5)).toBe(bezier(0,0, 0,0, 1,1, 1,1)(0.5)+""); } ); /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/ it("should be this for the value (the valid partion on a spline mode )", function() { + 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; + }; + }; + calc.mode = "spline"; + calc.keySplines = [0, 0.5, 0.5, 1]; + calc.to.degit = 1; + expect(calc.call()(0)).toBe(bezier(0,0, 0,0, 1,1, 1,1)(0)+".0"); + calc.to.from = from; + expect(calc.call()(1)).toBe(bezier(0,0, 0,0, 1,1, 1,1)(1)+".0"); + calc.to.from = from; } ); /*無効同値クラスを調べておく (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