OSDN Git Service

Lighten Math.cbrt function
authordhrname <dhrname@users.sourceforge.jp>
Sat, 28 Mar 2015 14:35:19 +0000 (23:35 +0900)
committerdhrname <dhrname@users.sourceforge.jp>
Sat, 28 Mar 2015 14:35:19 +0000 (23:35 +0900)
org/w3c/dom/smil.js
tool/Spec/spec/SvgDomSpec.js

index aa38a21..cfc4f13 100644 (file)
@@ -592,9 +592,8 @@ base("$from").of( {
            that = this,\r
            bezier = function (x1, y1, x2, y2, x3, y3, x4, y4) {\r
               return function (x) {\r
-                var a = [x4-3*(x3-x2)-x1, 3*(x3-2*x2+x1), 3*(x2-x1), x1-x];\r
                 /*三次方程式の解から、ベジェ曲線のyを求める*/\r
-                var s = Math.carda(a),\r
+                var s = Math.carda([x4-3*(x3-x2)-x1, 3*(x3-2*x2+x1), 3*(x2-x1), x1-x]),\r
                     i = 0,\r
                     si,\r
                     t = 0;\r
@@ -605,9 +604,7 @@ base("$from").of( {
                   }\r
                   ++i;\r
                 }\r
-                console.log(t);\r
                 y = (y4-3*(y3-y2)-y1)*t*t*t + 3*(y3-2*y2+y1)*t*t + 3*(y2-y1)*t + y1;\r
-                console.log(s, y);\r
                 return f(y);\r
              };\r
            },\r
@@ -622,14 +619,14 @@ base("$from").of( {
    }\r
 } ).to = base("$from").$to;\r
 \r
-/*ニュートン・ラフソン法により立方根(3乗根)を求める。Math.powだと負の値に対応していないため\r
+/*立方根(3乗根)を求める。Math.powだと負の値に対応していないため\r
  * なお、ソースコードの著作権は Tomy氏が持っている(tomy@tk.airnet.ne.jp)\r
  * http://www5.airnet.ne.jp/tomy/cpro/sslib3.htm*/\r
 Math.cbrt = function (a) {\r
        if(a == 0.)     return 0.;\r
        var w = Math.pow(Math.abs(a), 1./ 3.);\r
        if(a < 0.)      w = -w;\r
-       return (w + 3. * a / (2. * w * w + a / w)) / 2.;\r
+       return w;\r
 };\r
 /*カルダノ法による三次方程式 a[0]x^3 + a[1]x^2 + a[2]x + a[3] の解を求める\r
  * なお、ソースコードの著作権は Tomy氏が持っている\r
index 18671f6..19045f9 100644 (file)
@@ -3275,7 +3275,9 @@ describe("SMIL Animation Spec", function() {
         b = b(Math.random());\r
         expect(Math.abs(calc.call()(b.x) - b.y.toFixed(10))).toBeLessThan(epsiron);\r
       };\r
-      ff([0, 0.5, 0.5, 1]);\r
+      for (var i=0;i<10000;++i) {\r
+        ff([0, 0.5, 0.5, 1]);\r
+      }\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