It turns out that blocks with 'let' vars are not traceable currently. Use vars for now :-(
authorBenjamin Smedberg <benjamin@smedbergs.us>
Mon, 15 Dec 2008 10:08:16 -0500
changeset 14 696ec5de44cc
parent 13 51e58ba88e40
child 15 c18b21740d39
push id4
push userbsmedberg@mozilla.com
push dateMon, 15 Dec 2008 15:08:20 +0000
It turns out that blocks with 'let' vars are not traceable currently. Use vars for now :-(
wordmap.js
--- a/wordmap.js
+++ b/wordmap.js
@@ -188,90 +188,89 @@ function getWords(text)
     if (commonWordMap.hasOwnProperty(word.toLowerCase()))
       continue;
     yield word;
   }
 }
 
 function hitTest(fullimg, wordimg, x, y)
 {
-  let wdata = wordimg.data;
-  let fdata = fullimg.data;
+  var wdata, fdata, wy, widx, widxend, fidx, wv, fv;
+
+  wdata = wordimg.data;
+  fdata = fullimg.data;
 
   if (x < 0 || y < 0 ||
       x + wordimg.width > fullimg.width ||
       y + wordimg.height > fullimg.height)
     throw new Error("Bad args to hitTest: " + [x, y, wordimg.width, wordimg.height] + Error().stack);
 
   if (fullimg.minx === undefined)
     throw Error("Nothing placed on fullimg yet?");
 
   if (x > fullimg.maxx ||
       y > fullimg.maxy ||
       x + wordimg.width < fullimg.minx ||
       y + wordimg.height < fullimg.miny) {
     return false;
   }
 
-  for (let wy = wordimg.height - 1; wy >= 0; --wy) {
-    let widx = wy * wordimg.width * 4;
-    let widxend = widx + (wordimg.width * 4);
+  for (wy = wordimg.height - 1; wy >= 0; --wy) {
+    widx = wy * wordimg.width * 4;
+    widxend = widx + (wordimg.width * 4);
 
-    let fidx = ((y + wy) * fullimg.width + x) * 4;
+    fidx = ((y + wy) * fullimg.width + x) * 4;
     for (; widx < widxend; widx += 4, fidx += 4) {
 
       // + 3 is the opacity component
-      let wv = wdata[widx + 3];
-      let fv = fdata[fidx + 3];
-
-      /*
-      if (wv === undefined)
-	throw new Error("Word index out of bounds");
-      if (fv === undefined)
-	throw new Error("Full index out of bounds");
-       */
+      wv = wdata[widx + 3];
+      fv = fdata[fidx + 3];
 
       if (wv && fv)
 	return true;
     }
   }
   return false;
 }
 
 function slide(fullimg, wordimg, x1, y1, x2, y2)
 {
-  let hitting = hitTest(fullimg, wordimg, x1, y1);
+  var hitting, steps, step, ix, iy;
 
-  let steps = Math.max(Math.abs(x2 - x1), Math.abs(y2 - y1));
+  hitting = hitTest(fullimg, wordimg, x1, y1);
 
-  for (let step = 0; step < steps; ++step) {
-    let ix = Math.floor(x1 + (x2 - x1) * step / steps);
-    let iy = Math.floor(y1 + (y2 - y1) * step / steps);
+  steps = Math.max(Math.abs(x2 - x1), Math.abs(y2 - y1));
+
+  for (step = 0; step < steps; ++step) {
+    ix = Math.floor(x1 + (x2 - x1) * step / steps);
+    iy = Math.floor(y1 + (y2 - y1) * step / steps);
     if (hitTest(fullimg, wordimg, ix, iy) != hitting)
       return [ix, iy];
   }
 
   return [null, null];
 }
 
 function merge(fullimg, wordimg, x, y)
 {
-  let wdata = wordimg.data;
-  let fdata = fullimg.data;
+  var wdata, fdata, wy, widx, widxend, fidx;
+
+  wdata = wordimg.data;
+  fdata = fullimg.data;
 
   if (x < 0 || y < 0 ||
       x + wordimg.width > fullimg.width ||
       y + wordimg.height > fullimg.height)
     throw new Error("Bad args to merge");
 
-  for (let wy = wordimg.height - 1; wy >= 0; --wy) {
-    let widx = wy * wordimg.width * 4;
-    let widxend = widx + (wordimg.width * 4);
+  for (wy = wordimg.height - 1; wy >= 0; --wy) {
+    widx = wy * wordimg.width * 4;
+    widxend = widx + (wordimg.width * 4);
 
-    let fidx = ((y + wy) * fullimg.width + x) * 4;
+    fidx = ((y + wy) * fullimg.width + x) * 4;
     for (; widx < widxend; widx += 4, fidx += 4) {
       if (wdata[widx + 3]) {
 	// if the word bit has opacity
 	fdata[fidx] = wdata[widx];
 	fdata[fidx + 1] = wdata[widx + 1];
 	fdata[fidx + 2] = wdata[widx + 2];
 	fdata[fidx + 3] = wdata[widx + 3];
       }