OSDN Git Service

Add a from property to the object
authordhrname <dhrname@users.sourceforge.jp>
Fri, 6 Mar 2015 14:10:45 +0000 (23:10 +0900)
committerdhrname <dhrname@users.sourceforge.jp>
Fri, 6 Mar 2015 14:10:45 +0000 (23:10 +0900)
org/w3c/dom/smil.js
tool/Spec/spec/SvgDomSpec.js

index b24eaaf..55429ed 100644 (file)
@@ -460,13 +460,13 @@ base("$from").of( {
   strList: function() {\r
     return this.string.match(/[^\d\-\+\.eE]+/g);\r
   },\r
-\r
-  /*計算モード。advanceメソッドで時間の圧縮率を求めるのに使う*/\r
-  calc: base("$calcMode"),\r
+  \r
+  from: base("$from").up().mix( {\r
+          from: null\r
+        } ),\r
   \r
   /*$toオブジェクトにこのオブジェクトを適用させる関数*/\r
   call: function() {\r
-    this.$to.from = this;\r
     /*文字部分の配置パターンは4通りあるので、ここでstrListを処理\r
      * (1) a 0 の場合\r
      * (2) 0 a\r
@@ -504,13 +504,12 @@ base("$from").of( {
       if (!this.string || !this.from) {\r
         return "";\r
       }\r
-      /*時間の圧縮率をもとに変換 ($calcMode オブジェクトを参照)*/\r
-      t = this.calc(t);\r
       var str = "",\r
           numList = this.numList,\r
           strList = this.strList,\r
-          fromNumList = this.from.numList,\r
+          fromNumList = this.from,\r
           deg = this.degit;\r
+      \r
       for (var i=0,nuli=numList.length;i<nuli;++i) {\r
         /*$fromと$toを、原点Oからの二つのベクトル (n次空間のベクトル)と考える*/\r
         str += ( t * numList[i] + (1 - t) * fromNumList[i] ).toFixed(deg);\r
@@ -531,10 +530,13 @@ base("$from").of( {
        var toList = this.call(),\r
            fromList = from.call(),\r
            s = 0;\r
+       if (!toList || !fromList) {\r
+         return 0;\r
+       }\r
        for (var i=0, tli=toList.length; i<tli; ++i) {\r
-         s += toList[i]*toList[i] - fromList[i]*fromList[i];\r
+         s += (toList[i] - fromList[i])*(toList[i] - fromList[i]);\r
        }\r
-       return s;\r
+       return Math.sqrt(s);\r
      }\r
   } )\r
   /*fromプロパティの初期化*/\r
@@ -555,12 +557,14 @@ base("$from").of( {
    /*keySpline属性の値を設定*/\r
    keySpline: null,\r
    \r
+   from: base("$from"),\r
+   \r
    /*与えられたアニメーションの進捗率を使った時間の圧縮率を計算するための関数を返す*/\r
    call: function() {\r
      return function(t) {\r
        /*tは進捗率*/\r
        if (!this.keyTime) {\r
-         return 0;\r
+         t = 0;\r
        } \r
        return t / this.keyTime;\r
      }.bind(this);\r
index a0b7a17..d344c6f 100644 (file)
@@ -2811,7 +2811,8 @@ describe("SMIL Animation Spec", function() {
   describe("A $from object", function() {\r
     var from = base("$from");\r
      beforeEach( function() {\r
-       from = from.up();\r
+       from = base("$from").up();\r
+       from.from = from.from.up();\r
        from.string = "";\r
      } );\r
     /*境界条件を調べておく (limit value analysis)*/\r
@@ -2890,7 +2891,7 @@ describe("SMIL Animation Spec", function() {
       expect(from.numList()[1]).toBe(-1);\r
       expect(from.strList().join("")).toBe("ba");\r
 \r
-      from.up().call();\r
+      expect(from.up().call()).toBe(from.$1.numList);\r
       expect(from.$1.numList[1]).toBe(-1);\r
       expect(from.$1.strList.join("")).toBe("ba");\r
 \r
@@ -2936,6 +2937,7 @@ describe("SMIL Animation Spec", function() {
     /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
     it("should be this for the value (the valid partion)", function() {\r
       from.up("$to");\r
+      from.$to.from = from;\r
       from.$to.string = "12cm-7";\r
       expect(from.$to.numList().join(",")).toBe("12,-7");\r
       expect(from.$to.strList().toString()).toBe("cm");\r
@@ -2947,7 +2949,7 @@ describe("SMIL Animation Spec", function() {
       expect(from.$to.strList.join("")).toBe("cm");\r
       expect(from.numList.join(",")).toBe("7,8");\r
       expect(from.strList.join("")).toBe("cm");\r
-      expect(from.$to.from).toBe(from);\r
+      expect(from.$to.from).toBe(from.numList);\r
 \r
     } );\r
     /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
@@ -2967,6 +2969,7 @@ describe("SMIL Animation Spec", function() {
          from = base("$from").up();\r
          from.string = "";\r
          from.up("$to");\r
+         from.$to.from = from;\r
        } );\r
       /*境界条件を調べておく (limit value analysis)*/\r
       it("should be this for the value  (limit value analysis)", function() {\r
@@ -2986,12 +2989,13 @@ describe("SMIL Animation Spec", function() {
         expect(from.$to.call()).toBe(from.$to.numList);\r
         expect(from.$to.numList[0]).toEqual(1);\r
         expect(from.$to.strList).toBeNull();\r
-        expect(from.call()).toBe(from.numList);\r
         expect(from.numList[0]).toEqual(0);\r
         expect(from.strList).toBeNull();\r
         expect(from.advance(0)).toBe("");\r
-        expect(from.$to.from).toBe(from);\r
-        expect(from.$to.advance(0)).toBe("0");        \r
+        expect(from.$to.from).toBe(from.numList);\r
+        console.log(from.$to.from);\r
+        expect(from.$to.advance(0)).toBe("0");       \r
+        expect(from.call()).toBe(from.numList);\r
       } );\r
       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
       it("should be this for the value (the valid partion)", function() {\r
@@ -3002,42 +3006,43 @@ describe("SMIL Animation Spec", function() {
         expect(from.$to.call()).toBe(from.$to.numList);\r
         expect(from.$to.numList[0]).toEqual(1);\r
         expect(from.$to.strList[0]).toEqual("");\r
-        expect(from.call()).toBe(from.numList);\r
         expect(from.numList[0]).toEqual(0);\r
         expect(from.strList[0]).toEqual("");\r
         expect(from.advance(0)).toBe("");\r
-        expect(from.$to.from).toBe(from);\r
+        expect(from.$to.from).toBe(from.numList);\r
         expect(from.$to.advance(0)).toBe("0s");\r
         from.$to.degit = deg;\r
         for (var i=0;i<1;i+=0.01) {\r
           expect(from.$to.advance(i)).toBe(i.toFixed(deg)+"s");\r
         }\r
+        expect(from.call()).toBe(from.numList);\r
         \r
         from = base("$from").up();\r
         from.up("$to");\r
         from.string = "a0s";\r
         from.$to.string = "a1s";\r
+        from.$to.from = from;\r
         expect(from.$to.call()).toBe(from.$to.numList);\r
         expect(from.$to.numList[0]).toEqual(1);\r
         expect(from.$to.strList[0]).toEqual("a");\r
-        expect(from.call()).toBe(from.numList);\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.from).toBe(from.numList);\r
         expect(from.$to.advance(0)).toBe("a0s");\r
 \r
         from.$to.degit = deg;\r
         for (var i=0;i<1;i+=0.01) {\r
           expect(from.$to.advance(i)).toBe("a" +i.toFixed(deg)+ "s");\r
         }\r
+        expect(from.call()).toBe(from.numList);\r
         \r
         from = base("$from").up();\r
         from.up("$to");\r
         from.string = "a-10s1.5";\r
         from.$to.string = "a10s-3";\r
+        from.$to.from = from;\r
         from.$to.call();\r
-        from.call();\r
         from.$to.degit = 1;\r
         expect(from.$to.advance(0)).toEqual("a-10.0s1.5");\r
         expect(from.$to.advance(0.4)).toEqual("a-2.0s-0.3");\r
@@ -3073,17 +3078,31 @@ describe("SMIL Animation Spec", function() {
       } );\r
       /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
       it("should be this for the value (the valid partion)", function() {\r
+        from.string = "s 0 s 12";\r
+        from.$to.string = "s 0 s 0";\r
+        expect(from.distance()).toEqual(0);\r
+        expect(from.$to.distance(from)).toEqual(12);\r
+\r
+        from = base("$from").up();\r
+        from.up("$to");\r
+        from.string = "rgb(1, 0, 0)";\r
+        from.$to.string = "rgb(0, 0, 1)";\r
+        expect(from.distance()).toEqual(0);\r
+        expect(from.$to.distance(from)).toEqual(Math.sqrt(2));\r
       } );\r
       /*無効同値クラスを調べておく (Equivalence partitioning, the following is the invalid partion)*/\r
       it("should be this for the value (the invalid partion)", function() {\r
+        from.string = "s";\r
+        from.$to.string = "s";\r
+        expect(from.$to.distance(from)).toEqual(0);\r
       } );\r
    } );\r
   describe("A $calcMode object", function() {\r
     var calc = base("$calcMode"),\r
-        from = base("$from");\r
+        from = calc.from;\r
      beforeEach( function() {\r
        calc = calc.up();\r
-       from = from.up();\r
+       calc.from = from = from.up();\r
        from.up("$to");\r
      } );\r
     /*境界条件を調べておく (limit value analysis)*/\r
@@ -3092,9 +3111,9 @@ describe("SMIL Animation Spec", function() {
       expect(calc.keyTime).toEqual(1);\r
       expect(calc.keySpline).toBeNull();\r
 \r
-      expect(calc.call()(0)).toEqual(0);\r
+      expect(calc.call()(0)).toBe("0");\r
       expect(calc.keyTime).toBe(1);\r
-      expect(calc.call()(1)).toEqual(1);\r
+      expect(calc.call()(1)).toBe("1");\r
     } );\r
     /*同値分割をして、有効同値クラスを調べておく (Equivalence partitioning, the following is the valid partion)*/\r
     it("should be this for the value (the valid partion)", function() {\r
@@ -3104,8 +3123,8 @@ describe("SMIL Animation Spec", function() {
       /*もう一度確かめる*/\r
       expect(calc.call()(0.2)).toEqual(0.4);\r
       \r
-      from.$to.calc = from.calc.up();\r
-      from.$to.calc.keyTime = 0.2;\r
+      calc = base("$calcMode").up();\r
+      calc.keyTime = 0.2;\r
       from.string = "0s";\r
       from.$to.string = "1s";\r
       from.$to.degit = 1;\r