OSDN Git Service

Support an advance method for the present value
authordhrname <dhrname@users.sourceforge.jp>
Fri, 27 Feb 2015 13:13:25 +0000 (22:13 +0900)
committerdhrname <dhrname@users.sourceforge.jp>
Fri, 27 Feb 2015 13:13:25 +0000 (22:13 +0900)
org/w3c/dom/smil.js
tool/Spec/spec/SvgDomSpec.js

index 986a182..1c94175 100644 (file)
@@ -464,13 +464,34 @@ base("$from").of( {
   /*$toオブジェクトにこのオブジェクトを適用させる関数*/\r
   call: function() {\r
     this.$to.from = this;\r
+    /*文字部分の配置パターンは4通りあるので、ここでstrListを処理\r
+     * (1) a 0 の場合\r
+     * (2) 0 a\r
+     * (3) a 0 a (ノーマルパターン)\r
+     * (4) 0 a 0\r
+     * これらのパターンのうち、(1)(2)(4)を(3)のパターンに変えたのが以下*/\r
+    /*文字列が1aのように、数値で始まるかどうか。始まったら真*/\r
+    if (!this.string || !this.numList || !this.strList) {\r
+      return this.$to;\r
+    }\r
+    var isFirstNum = /^[\-\+]?[\d\.]/.test(this.string),\r
+    /*文字列がa1のように、数値で終わるかどうか。終わったら真*/\r
+        isLastNum = /\d$/.test(this.string),\r
+        isNormal = (this.numList.length < this.strList.length);\r
+    if (isFirstNum && !isNormal) {\r
+      this.strList.unshift("");\r
+    }\r
+    if (isLastNum && !isNormal) {\r
+      this.strList.push("");\r
+    }\r
     return this.$to;\r
   }\r
     \r
 } )\r
  .mix( {   \r
    /*advance メソッド\r
-    * アニメーションの進行具合を示す進捗率 t (0 <= t <= 1)をもとに、現在の呈示値を算出するためのもの*/\r
+    * アニメーションの進行具合を示す進捗率 t (0 <= t <= 1)をもとに、現在の呈示値を算出するためのもの\r
+    * callメソッドで前もって呼び出されていることが前提となる*/\r
     advance: function(t) {\r
       if ( (t < 0) || (1 < t)) {\r
         throw new Error("An Invalid Number Error");\r
@@ -483,11 +504,12 @@ base("$from").of( {
           strList = this.strList,\r
           fromNumList = this.from.numList;\r
       for (var i=0,nuli=numList.length;i<nuli;++i) {\r
-        /*$fromと$toを、原点Oから伸びる二つのベクトル (n次空間のベクトル)と考え、\r
-         * そのベクトルの端同士を結ぶ線上の点Pをベクトルの計算から求める*/\r
+        /*$fromと$toを、原点Oからの二つのベクトル (n次空間のベクトル)と考える*/\r
         str += ( t * numList[i] + (1 - t) * fromNumList[i] );\r
-        strList && ( str += strList[i] );\r
+        strList && ( str += strList[i+1] );\r
       }\r
+      /*文字列はcallメソッドにより、a0aのパターンになっているので、aの部分を追加*/\r
+      str = (strList ? strList[0] : "") + str;\r
       numList = strList = fromNumList = i = nuli = void 0;\r
       return str;\r
     }\r
index 7fc9af6..f04ff1e 100644 (file)
@@ -2944,9 +2944,9 @@ describe("SMIL Animation Spec", function() {
       from.$to.call();\r
       expect(from.call()).toBe(from.$to);\r
       expect(from.$to.numList.join(",")).toBe("12,-7");\r
-      expect(from.$to.strList.toString()).toBe("cm");\r
+      expect(from.$to.strList.join("")).toBe("cm");\r
       expect(from.numList.join(",")).toBe("7,8");\r
-      expect(from.strList.toString()).toBe("cm");\r
+      expect(from.strList.join("")).toBe("cm");\r
       expect(from.$to.from).toBe(from);\r
 \r
     } );\r
@@ -2999,13 +2999,33 @@ describe("SMIL Animation Spec", function() {
         from.$to.string = "1s";\r
         expect(from.$to.call()).toBe(from.$to);\r
         expect(from.$to.numList[0]).toEqual(1);\r
-        expect(from.$to.strList[0]).toEqual("s");\r
+        expect(from.$to.strList[0]).toEqual("");\r
         expect(from.call()).toBe(from.$to);\r
         expect(from.numList[0]).toEqual(0);\r
-        expect(from.strList[0]).toEqual("s");\r
+        expect(from.strList[0]).toEqual("");\r
         expect(from.advance(0)).toBe("");\r
         expect(from.$to.from).toBe(from);\r
-        expect(from.$to.advance(0)).toBe("0s");        \r
+        expect(from.$to.advance(0)).toBe("0s");\r
+        for (var i=0;i<1;i+=0.01) {\r
+          expect(from.$to.advance(i)).toBe(i+"s");\r
+        }\r
+        \r
+        from = base("$from").up();\r
+        from.up("$to");\r
+        from.string = "a0s";\r
+        from.$to.string = "a1s";\r
+        expect(from.$to.call()).toBe(from.$to);\r
+        expect(from.$to.numList[0]).toEqual(1);\r
+        expect(from.$to.strList[0]).toEqual("a");\r
+        expect(from.call()).toBe(from.$to);\r
+        expect(from.numList[0]).toEqual(0);\r
+        expect(from.strList[0]).toEqual("a");\r
+        expect(from.advance(0)).toBe("");\r
+        expect(from.$to.from).toBe(from);\r
+        expect(from.$to.advance(0)).toBe("a0s");\r
+        for (var i=0;i<1;i+=0.01) {\r
+          expect(from.$to.advance(i)).toBe("a" +i+ "s");\r
+        }\r
       } );\r
       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
       it("should be this for the value (the invalid partion)", function() {\r