OSDN Git Service

Support a 'spline' mode
authordhrname <dhrname@users.sourceforge.jp>
Fri, 20 Mar 2015 14:28:31 +0000 (23:28 +0900)
committerdhrname <dhrname@users.sourceforge.jp>
Fri, 20 Mar 2015 14:28:31 +0000 (23:28 +0900)
org/w3c/dom/smil.js
tool/Spec/spec/SvgDomSpec.js

index dc74da7..cfe1c6d 100644 (file)
@@ -557,7 +557,7 @@ base("$from").of( {
    keyTime: 1,\r
    \r
    /*keySpline属性の値を設定*/\r
-   keySpline: null,\r
+   keySplines: null,\r
    \r
    /*全体の行列ノルム(距離)*/\r
    norm: 1,\r
@@ -586,6 +586,17 @@ base("$from").of( {
        this.keyTime = this.to.distance(this.to.from) / this.norm;\r
        return f;\r
      } else if (this.mode === "spline") {\r
+      var x = 0,\r
+          y = 0,\r
+          bezier = function (x1, y1, x2, y2, x3, y3, x4, y4) {\r
+            return function (t) {\r
+              x = (x4-3*(x3+x2)-x1)*t*t*t + 3*(x3-2*x2+x1)*t*t + 3*(x2-x1)*t + x1;\r
+              y = (y4-3*(y3+y2)-y1)*t*t*t + 3*(y3-2*y2+y1)*t*t + 3*(y2-y1)*t + y1;\r
+              return y+"";\r
+            };\r
+          },\r
+          tk = this.keySplines;\r
+       return bezier(0, 0, tk[0], tk[1], tk[2], tk[3], 1, 1);\r
      } else if (this.mode === "discrete") {\r
        return function (t) {\r
          return isNaN(t) ? this.string\r
index 509e879..2f4a21c 100644 (file)
@@ -3109,7 +3109,7 @@ describe("SMIL Animation Spec", function() {
     it("should be this for the value  (limit value analysis)", function() {\r
       expect(calc.mode).toBe("linear");\r
       expect(calc.keyTime).toEqual(1);\r
-      expect(calc.keySpline).toBeNull();\r
+      expect(calc.keySplines).toBeNull();\r
 \r
       expect(calc.call()(0)).toBe("0");\r
       expect(calc.keyTime).toBe(1);\r
@@ -3187,6 +3187,13 @@ describe("SMIL Animation Spec", function() {
       calc.to = base("$from").up();\r
       calc.to.from = base("$from").up();    \r
       calc.mode = "discrete";\r
+      calc.keyTime = 0.5;\r
+      calc.to.degit = 1;\r
+      calc.to.string = "0.5";\r
+      expect(calc.call()(0.2)).toBe("0.5");\r
+      expect(calc.call()(0.3)).toBe("0.5");\r
+      /*もう一度確かめる*/\r
+      expect(calc.call()(0.2)).toBe("0.5");\r
     } );\r
     /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
     it("should be this for the value (the invalid partion)", function() {\r
@@ -3207,5 +3214,29 @@ describe("SMIL Animation Spec", function() {
       calc.mode = "discrete";\r
       expect(calc.call()()).toEqual(calc.string);\r
     } );\r
+    /*splineモードの境界条件を調べておく (limit value analysis)*/\r
+    it("should be this for the value  (spline mode limit value analysis)", function() {\r
+      /*3次ベジェ曲線の数式はこのページを参考にした http://geom.web.fc2.com/geometry/bezier/cubic.html*/\r
+      var x = 0,\r
+          y = 0,\r
+          bezier = function (x1, y1, x2, y2, x3, y3, x4, y4) {\r
+            return function (t) {\r
+              x = (x4-3*(x3+x2)-x1)*t*t*t + 3*(x3-2*x2+x1)*t*t + 3*(x2-x1)*t + x1;\r
+              y = (y4-3*(y3+y2)-y1)*t*t*t + 3*(y3-2*y2+y1)*t*t + 3*(y2-y1)*t + y1;\r
+              return y;\r
+            };\r
+          };\r
+      expect(calc.keySplines).toBeNull();\r
+      calc.mode = "spline";\r
+      calc.keySplines = [0, 0, 1, 1];\r
+      expect(calc.call()(0)).toBe(bezier(0,0, 0,0, 1,1, 1,1)(0)+"");\r
+      expect(calc.call()(1)).toBe(bezier(0,0, 0,0, 1,1, 1,1)(1)+"");\r
+    } );\r
+    /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
+    it("should be this for the value (the valid partion on a spline mode )", function() {\r
+    } );\r
+    /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
+    it("should be this for the value (the invalid partion on a spline mode )", function() {\r
+    } );\r
   } );\r
 } );\r