[Sie-announce] SIEコード [2485] SVGPathElementの連続したvar文を整理して軽量化

Zurück zum Archiv-Index

svnno****@sourc***** svnno****@sourc*****
2011年 3月 18日 (金) 23:27:42 JST


Revision: 2485
          http://sourceforge.jp/projects/sie/svn/view?view=rev&revision=2485
Author:   dhrname
Date:     2011-03-18 23:27:42 +0900 (Fri, 18 Mar 2011)

Log Message:
-----------
SVGPathElementの連続したvar文を整理して軽量化

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

Modified: branches/07x/073/org/w3c/dom/svg.js
===================================================================
--- branches/07x/073/org/w3c/dom/svg.js	2011-03-17 12:25:35 UTC (rev 2484)
+++ branches/07x/073/org/w3c/dom/svg.js	2011-03-18 14:27:42 UTC (rev 2485)
@@ -2416,7 +2416,9 @@
        * 
        *SVG1.1 「8.3.9 The grammar for path data」の項目にある最後の文章を参照
        */
-      var tnl = tar.normalizedPathSegList, tlist = tar.pathSegList, D = [];
+      var tnl = tar.normalizedPathSegList,
+          tlist = tar.pathSegList,
+          D = [];
       if (tnl.numberOfItems > 0) {
         tnl.clear();
         tlist.clear();
@@ -2425,8 +2427,9 @@
        *JSONにおける表現は以下のとおり
        *D = [["M", 20, 30], ["L", 20 40]]
        */
-      var taco = tar._com, sgs = taco.isSp;
-      var dd = evt.newValue
+      var taco = tar._com,
+          sgs = taco.isSp,
+          dd = evt.newValue
       .replace(taco.isRa, " -")
       .replace(taco.isRb, " ")
       .replace(taco.isRc, ",$1 ")
@@ -2506,11 +2509,13 @@
       /*以下の処理は、pathSegListからnormalizedPathSegListへの
        *変換をする処理。相対座標を絶対座標に変換して、M、L、Cコマンドに正規化していく
        */
-      var cx = 0, cy = 0;         //現在セグメントの終了点の絶対座標を示す (相対座標を絶対座標に変換するときに使用)
-      var xn = 0, yn = 0;         //T,tコマンドで仮想的な座標を算出するのに用いる。第一コントロール点
-      var startx = 0, starty = 0; //M,mコマンドにおける始点座標(Z,zコマンドで用いる)
+      var cx = 0, cy = 0,         //現在セグメントの終了点の絶対座標を示す (相対座標を絶対座標に変換するときに使用)
+          xn = 0, yn = 0,         //T,tコマンドで仮想的な座標を算出するのに用いる。第一コントロール点
+          startx = 0, starty = 0; //M,mコマンドにおける始点座標(Z,zコマンドで用いる)
       for (var j=0, tli=tlist.numberOfItems;j<tli;++j) {
-        var ti = tlist.getItem(j), ts = ti.pathSegType, dii = ti.pathSegTypeAsLetter;
+        var ti = tlist.getItem(j),
+            ts = ti.pathSegType,
+            dii = ti.pathSegTypeAsLetter;
         if (ts === SVGPathSeg.PATHSEG_UNKNOWN) {
         } else {
           var rx = cx, ry = cy;   //rx, ryは前のセグメントの終了点
@@ -2576,19 +2581,23 @@
                *SVG 1.1 「F.6 Elliptical arc implementation notes」の章を参照
                *http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
                */
-              var fS = ti.sweepFlag, psai = ti.angle;
               if (ti.r1 === 0 || ti.r2 === 0) {
                 return;
               }
-              var r1 = _math.abs(ti.r1);
-              var r2 = _math.abs(ti.r2);
-              var ctx = (rx - cx) / 2,  cty = (ry - cy) / 2;
-              var cpsi = _math.cos(psai * _math.PI / 180), spsi = _math.sin(psai * _math.PI / 180);
-              var rxd = cpsi*ctx + spsi*cty,  ryd = -1*spsi*ctx + cpsi*cty;
-              var rxdd = rxd * rxd, rydd = ryd * ryd;
-              var r1x = r1 * r1, r2y = r2 * r2;
-              var lamda = rxdd/r1x + rydd/r2y;
-              var sds;
+              var fS = ti.sweepFlag,
+                  psai = ti.angle,
+                  r1 = _math.abs(ti.r1),
+                  r2 = _math.abs(ti.r2),
+                  ctx = (rx - cx) / 2,  cty = (ry - cy) / 2,
+                  cpsi = _math.cos(psai * _math.PI / 180),
+                  spsi = _math.sin(psai * _math.PI / 180),
+                  rxd = cpsi*ctx + spsi*cty,
+                  ryd = -1*spsi*ctx + cpsi*cty,
+                  rxdd = rxd * rxd, rydd = ryd * ryd,
+                  r1x = r1 * r1,
+                  r2y = r2 * r2,
+                  lamda = rxdd/r1x + rydd/r2y,
+                  sds;
               if (lamda > 1) {
                 r1 = _math.sqrt(lamda) * r1;
                 r2 = _math.sqrt(lamda) * r2;
@@ -2600,32 +2609,37 @@
                 }
                 sds = seif * _math.sqrt((r1x*r2y - r1x*rydd - r2y*rxdd) / (r1x*rydd + r2y*rxdd));
               }
-              var txd = sds*r1*ryd / r2,  tyd = -1 * sds*r2*rxd / r1;
-              var tx = cpsi*txd - spsi*tyd + (rx+cx)/2, ty = spsi*txd + cpsi*tyd + (ry+cy)/2;
-              var rad = _math.atan2((ryd-tyd)/r2, (rxd-txd)/r1) - _math.atan2(0, 1);
-              var s1 = (rad >= 0) ? rad : 2 * _math.PI + rad;
-              rad = _math.atan2((-ryd-tyd)/r2, (-rxd-txd)/r1) - _math.atan2((ryd-tyd)/r2, (rxd-txd)/r1);
-              var dr = (rad >= 0) ? rad : 2 * _math.PI + rad;
+              var txd = sds*r1*ryd / r2,
+                  tyd = -1 * sds*r2*rxd / r1,
+                  tx = cpsi*txd - spsi*tyd + (rx+cx)/2,
+                  ty = spsi*txd + cpsi*tyd + (ry+cy)/2,
+                  rad = _math.atan2((ryd-tyd)/r2, (rxd-txd)/r1) - _math.atan2(0, 1),
+                  s1 = (rad >= 0) ? rad : 2 * _math.PI + rad,
+                  rad = _math.atan2((-ryd-tyd)/r2, (-rxd-txd)/r1) - _math.atan2((ryd-tyd)/r2, (rxd-txd)/r1),
+                  dr = (rad >= 0) ? rad : 2 * _math.PI + rad;
               if (!fS  &&  dr > 0) {
                 dr -=   2*_math.PI;
               } else if (fS  &&  dr < 0) {
                 dr += 2*_math.PI;
               }
-              var sse = dr * 2 / _math.PI;
-              var seg = _math.ceil(sse<0 ? -1*sse  :  sse);
-              var segr = dr / seg;
-              var t = 8/3 * _math.sin(segr/4) * _math.sin(segr/4) / _math.sin(segr/2);
-              var cpsir1 = cpsi * r1, cpsir2 = cpsi * r2;
-              var spsir1 = spsi * r1, spsir2 = spsi * r2;
-              var mc = _math.cos(s1);
-              var ms = _math.sin(s1);
-              var x2 = rx - t * (cpsir1*ms + spsir2*mc), y2 = ry - t * (spsir1*ms - cpsir2*mc);
+              var sse = dr * 2 / _math.PI,
+                  seg = _math.ceil(sse<0 ? -1*sse  :  sse),
+                  segr = dr / seg,
+                  t = 8/3 * _math.sin(segr/4) * _math.sin(segr/4) / _math.sin(segr/2),
+                  cpsir1 = cpsi * r1, cpsir2 = cpsi * r2,
+                  spsir1 = spsi * r1, spsir2 = spsi * r2,
+                  mc = _math.cos(s1),
+                  ms = _math.sin(s1),
+                  x2 = rx - t * (cpsir1*ms + spsir2*mc),
+                  y2 = ry - t * (spsir1*ms - cpsir2*mc);
               for (var n = 0; n < seg; ++n) {
                 s1 += segr;
                 mc = _math.cos(s1);
                 ms = _math.sin(s1);
-                var x3 = cpsir1*mc - spsir2*ms + tx, y3 = spsir1*mc + cpsir2*ms + ty;
-                var dx = -t * (cpsir1*ms + spsir2*mc), dy = -t * (spsir1*ms - cpsir2*mc);
+                var x3 = cpsir1*mc - spsir2*ms + tx,
+                    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));
                 x2 = x3 + dx;
                 y2 = y3 + dy;
@@ -2635,13 +2649,15 @@
             if (j !== 0) {
               var tg = tnl.getItem(tnl.numberOfItems-1);
               if (tg.pathSegTypeAsLetter === "C") {
-                var x1 = 2*tg.x - tg.x2;
-                var y1 = 2*tg.y - tg.y2;
+                var x1 = 2*tg.x - tg.x2,
+                    y1 = 2*tg.y - tg.y2;
               } else { //前のコマンドがCでなければ、現在の座標を第1コントロール点に用いる
-                var x1 = rx, y1 = ry;
+                var x1 = rx,
+                    y1 = ry;
               }
             } else {
-              var x1 = rx, y1 = ry;
+              var x1 = rx,
+                  y1 = ry;
             }
             tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, x1, y1, ti.x2, ti.y2));
             x1 = y1 = null;
@@ -2649,13 +2665,15 @@
             if (j !== 0) {
               var tg = tnl.getItem(tnl.numberOfItems-1);
               if (tg.pathSegTypeAsLetter === "C") {
-                var x1 = 2*tg.x - tg.x2;
-                var y1 = 2*tg.y - tg.y2;
+                var x1 = 2*tg.x - tg.x2,
+                    y1 = 2*tg.y - tg.y2;
               } else {
-                var x1 = rx, y1 = ry;
+                var x1 = rx,
+                    y1 = ry;
               }
             } else {
-              var x1 = rx, y1 = ry;
+              var x1 = rx,
+                  y1 = ry;
             }
             tnl.appendItem(tar.createSVGPathSegCurvetoCubicAbs(cx, cy, x1, y1, ti.x2+rx, ti.y2+ry));
             x1 = y1 = null;
@@ -2693,7 +2711,9 @@
     if (evt.eventPhase === /*Event.BUBBLING_PHASE*/ 3) {
       return; //強制終了させる
     }
-    var tnext = tar.nextSibling, tpar = tar.parentNode, isLast = true;
+    var tnext = tar.nextSibling,
+        tpar = tar.parentNode,
+        isLast = true;
     if (tnext && tnext._tar && tpar._tar && (tnext._tar.parentNode === tpar._tar)) {
       tpar._tar.insertBefore(tar._tar, tnext._tar);
     } else if (tnext && !tnext._tar && tpar._tar) {
@@ -2718,12 +2738,18 @@
       /*以下の処理は、normalizedpathSegListとCTMに基づいて、
        *SVGのd属性をVMLに変換していく処理である。
        */
-      var tar = evt.target, matrix = tar.getScreenCTM(), tlist = tar.normalizedPathSegList, _parseInt = _pInt;
-      var dat = [], ma = matrix.a, mb = matrix.b, mc = matrix.c, md = matrix.d, me = matrix.e, mf = matrix.f;
-      var cname = tar._com._nameCom, isZ = tar._com._isZ, isC = tar._com._isC;
+      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,
+          isZ = tar._com._isZ, isC = tar._com._isC;
       for (var i=0, tli=tlist.numberOfItems;i<tli;++i) {
-        var ti = tlist[i], tps = ti.pathSegTypeAsLetter;
-        var t = cname[tps];
+        var ti = tlist[i],
+            tps = ti.pathSegTypeAsLetter,
+            t = cname[tps];
         if (isC[tps]) {
           /*CTM(mx)の行列と座標(x, y)の積を算出する。数学における表現は以下のとおり
            *[ma mc me]   [x]
@@ -2741,8 +2767,9 @@
         }
         dat[i] = t;
       }
-      var vi = tar.ownerDocument.documentElement;
-      var w = vi.width.baseVal.value, h = vi.height.baseVal.value;
+      var vi = tar.ownerDocument.documentElement,
+          w = vi.width.baseVal.value,
+          h = vi.height.baseVal.value;
       dat[dat.length] = " e";
       tar._tar.path = dat.join(" ");
       tar._tar.coordsize = w + " " + h;




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