[Sie-announce] SIEコード [2527] SVGPathElementの最適化

Zurück zum Archiv-Index

svnno****@sourc***** svnno****@sourc*****
2011年 3月 29日 (火) 23:11:09 JST


Revision: 2527
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2527
Author:   dhrname
Date:     2011-03-29 23:11:09 +0900 (Tue, 29 Mar 2011)

Log Message:
-----------
SVGPathElementの最適化

Modified Paths:
--------------
    branches/07x/074/org/w3c/dom/svg.js

Modified: branches/07x/074/org/w3c/dom/svg.js
===================================================================
--- branches/07x/074/org/w3c/dom/svg.js	2011-03-29 13:39:52 UTC (rev 2526)
+++ branches/07x/074/org/w3c/dom/svg.js	2011-03-29 14:11:09 UTC (rev 2527)
@@ -2541,14 +2541,17 @@
        */
       var taco = tar._com,
           sgs = taco.isSp,
+          tccc = tar.createSVGPathSegCurvetoCubicAbs,
+          tcla = tar.createSVGPathSegLinetoAbs,
           dd = evt.newValue
       .replace(taco.isRa, " -")
       .replace(taco.isRb, " ")
       .replace(taco.isRc, ",$1 ")
       .replace(taco.isRd, ",$1 1")
       .replace(taco.isRe, "")
-      .split(",");
-      for (var i=0, dli=dd.length;i<dli;++i) {
+      .split(","),
+          dli=dd.length;
+      for (var i=0;i<dli;++i) {
         D[i] = dd[i].match(sgs);
         for (var j=1, dili=D[i].length;j<dili;++j) {
           D[i][j] = +(D[i][j]);
@@ -2556,7 +2559,7 @@
       }
       sgs = dd = null;
       var isZ = taco._isZ, isM = taco._isM, isC = taco._isC, isL = taco._isL;
-      for (var i=0, Dli=D.length; i < Dli; ++i) {
+      for (var i=0; i < dli; ++i) {
         var di = D[i], s;
         for (var j=1, dii=di[0], dili=di.length; j < dili; ++j) {
           if (isM[dii]) {
@@ -2566,13 +2569,13 @@
             s = tar.createSVGPathSegMovetoRel(di[j], di[j+1]);
             ++j;
           } else if (isL[dii]) {
-            s = tar.createSVGPathSegLinetoAbs(di[j], di[j+1]);
+            s = tcla(di[j], di[j+1]);
             ++j;
           } else if (dii === "l") {
             s = tar.createSVGPathSegLinetoRel(di[j], di[j+1]);
             ++j;
           } else if (isC[dii]) {
-            s = tar.createSVGPathSegCurvetoCubicAbs(di[j+4], di[j+5], di[j], di[j+1], di[j+2], di[j+3]);
+            s = tccc(di[j+4], di[j+5], di[j], di[j+1], di[j+2], di[j+3]);
             j += 5;
           } else if (dii === "c") {
             s = tar.createSVGPathSegCurvetoCubicRel(di[j+4], di[j+5], di[j], di[j+1], di[j+2], di[j+3]);
@@ -2646,7 +2649,7 @@
                */
               var tg = tlist.getItem(j-1);
               if (tg.pathSegTypeAsLetter === "M") {
-                tnl.appendItem(tar.createSVGPathSegLinetoAbs(cx, cy));
+                tnl.appendItem(tcla(cx, cy));
                 continue;
               }
             }
@@ -2657,7 +2660,7 @@
             if (j !== 0) {
               var tg = tlist.getItem(j-1);
               if (tg.pathSegTypeAsLetter === "m") {
-                tnl.appendItem(tar.createSVGPathSegLinetoAbs(cx, cy));
+                tnl.appendItem(tcla(cx, cy));
                 continue;
               }
             }
@@ -2667,11 +2670,11 @@
           } else if (isL[dii]) {
             tnl.appendItem(ti);
           } else if (dii === "l") {
-            tnl.appendItem(tar.createSVGPathSegLinetoAbs(cx, cy));
+            tnl.appendItem(tcla(cx, cy));
           } else if (isC[dii]) {
             tnl.appendItem(ti);
           } else if (dii === "c") {
-            tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, ti.x1+rx, ti.y1+ry, ti.x2+rx, ti.y2+ry));
+            tnl.appendItem(tccc(cx, cy, ti.x1+rx, ti.y1+ry, ti.x2+rx, ti.y2+ry));
           } else if (isZ[dii]) {
             cx = startx;
             cy = starty;
@@ -2680,12 +2683,12 @@
             xn = 2*cx - ti.x1;
             yn = 2*cy - ti.y1;
             //2次スプライン曲線は近似的な3次ベジェ曲線に変換している
-            tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, (rx + 2*ti.x1) / 3, (ry + 2*ti.y1) / 3, (2*ti.x1 + cx) / 3, (2*ti.y1 + cy) / 3));
+            tnl.appendItem(tccc(cx, cy, (rx + 2*ti.x1) / 3, (ry + 2*ti.y1) / 3, (2*ti.x1 + cx) / 3, (2*ti.y1 + cy) / 3));
           } else if (dii === "q") {
             var x1 = ti.x1 + rx, y1 = ti.y1 + ry;
             xn = 2*cx - x1;
             yn = 2*cy - y1;
-            tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, (rx + 2*x1) / 3, (ry + 2*y1) / 3, (2*x1 + cx) / 3, (2*y1 + cy) / 3));
+            tnl.appendItem(tccc(cx, cy, (rx + 2*x1) / 3, (ry + 2*y1) / 3, (2*x1 + cx) / 3, (2*y1 + cy) / 3));
             x1 = y1 = null;
           } else if (dii === "A" || dii === "a") {
             (function(ti, cx, cy, rx, ry, tar, tnl) { //変数を隠蔽するためのfunction
@@ -2752,7 +2755,7 @@
                     y3 = spsir1*mc + cpsir2*ms + ty,
                     dx = -t * (cpsir1*ms + spsir2*mc),
                     dy = -t * (spsir1*ms - cpsir2*mc);
-                tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(x3, y3, x2, y2, x3-dx, y3-dy));
+                tnl.appendItem(tccc(x3, y3, x2, y2, x3-dx, y3-dy));
                 x2 = x3 + dx;
                 y2 = y3 + dy;
               }
@@ -2771,7 +2774,7 @@
               var x1 = rx,
                   y1 = ry;
             }
-            tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, x1, y1, ti.x2, ti.y2));
+            tnl.appendItem(tccc(cx, cy, x1, y1, ti.x2, ti.y2));
             x1 = y1 = null;
           } else if (dii === "s") {
             if (j !== 0) {
@@ -2787,7 +2790,7 @@
               var x1 = rx,
                   y1 = ry;
             }
-            tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, x1, y1, ti.x2+rx, ti.y2+ry));
+            tnl.appendItem(tccc(cx, cy, x1, y1, ti.x2+rx, ti.y2+ry));
             x1 = y1 = null;
           } else if (dii === "T" || dii === "t") {
             if (j !== 0) {
@@ -2799,21 +2802,21 @@
             } else {
               xn = rx, yn = ry;
             }
-            tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, (rx + 2*xn) / 3, (ry + 2*yn) / 3, (2*xn + cx) / 3, (2*yn + cy) / 3));
+            tnl.appendItem(tccc(cx, cy, (rx + 2*xn) / 3, (ry + 2*yn) / 3, (2*xn + cx) / 3, (2*yn + cy) / 3));
             xn = 2*cx - xn;
             yn = 2*cy - yn;
             xx1 = yy1 = null;
           } else if (dii === "H" || dii === "h") {
-            tnl.appendItem(tar.createSVGPathSegLinetoAbs(cx, ry));
+            tnl.appendItem(tcla(cx, ry));
             cy = ry; //勝手にti.yが0としているため
           } else if (dii === "V" || dii === "v") {
-            tnl.appendItem(tar.createSVGPathSegLinetoAbs(rx, cy));
+            tnl.appendItem(tcla(rx, cy));
             cx = rx;
           }
         }
       }
     }
-    evt = tar = taco = cx = cy = xn = yn = startx = starty = tnl = tlist = ti = dii = ts = isZ = isM = isL = isC = s = null;
+    evt = tar = taco = cx = cy = xn = yn = startx = starty = tnl = tlist = ti = dii = ts = isZ = isM = isL = isC = s = tcla = tccc = null;
   }, false);
   /*以下の処理は、このpath要素ノードがDOMツリーに追加されて初めて、
    *描画が開始されることを示す。つまり、appendChildで挿入されない限り、描画をしない。
@@ -2853,7 +2856,6 @@
       var tar = evt.target,
           matrix = tar.getScreenCTM(),
           tlist = tar.normalizedPathSegList,
-          _parseInt = _pInt,
           dat = [],
           ma = matrix.a, mb = matrix.b, mc = matrix.c, md = matrix.d, me = matrix.e, mf = matrix.f,
           cname = tar._com._nameCom,
@@ -2868,14 +2870,14 @@
            *[mb md mf] * [y]
            *[0  0  1 ]   [1]
            */
-          t += ([_parseInt(ma*ti.x1 + mc*ti.y1 + me, 10),
-                 _parseInt(mb*ti.x1 + md*ti.y1 + mf, 10),
-                 _parseInt(ma*ti.x2 + mc*ti.y2 + me, 10),
-                 _parseInt(mb*ti.x2 + md*ti.y2 + mf, 10),
-                 _parseInt(ma*ti.x + mc*ti.y + me, 10),
-                 _parseInt(mb*ti.x + md*ti.y + mf, 10)]).join(" ");
+          t += ([ma*ti.x1 + mc*ti.y1 + me | 0,
+                 mb*ti.x1 + md*ti.y1 + mf | 0,
+                 ma*ti.x2 + mc*ti.y2 + me | 0,
+                 mb*ti.x2 + md*ti.y2 + mf | 0,
+                 ma*ti.x + mc*ti.y + me | 0,
+                 mb*ti.x + md*ti.y + mf | 0]).join(" ");
         } else if (!isZ[tps]) {
-          t += _parseInt(ma*ti.x + mc*ti.y + me, 10)+ " " +_parseInt(mb*ti.x + md*ti.y + mf, 10);
+          t += ma*ti.x + mc*ti.y + me | 0 + " " +mb*ti.x + md*ti.y + mf | 0;
         }
         dat[i] = t;
       }




Sie-announce メーリングリストの案内
Zurück zum Archiv-Index