Revision: 18584
          http://sourceforge.net/p/jmol/code/18584
Author:   hansonr
Date:     2013-08-17 02:51:29 +0000 (Sat, 17 Aug 2013)
Log Message:
-----------
work-around for Safari bug/Google Closure Compiler incompatibility vis-a-vis 
float/integer conversion.

Modified Paths:
--------------
    trunk/Jmol/appletweb/jsmol.zip
    trunk/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java
    trunk/Jmol/src/org/jmol/awtjs2d/Mouse.java
    trunk/Jmol/src/org/jmol/util/Escape.java
    trunk/Jmol/src/org/jmol/util/Parser.java

Modified: trunk/Jmol/appletweb/jsmol.zip
===================================================================
(Binary files differ)

Modified: trunk/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java
===================================================================
--- trunk/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java  2013-08-16 
16:30:06 UTC (rev 18583)
+++ trunk/Jmol/src/org/jmol/adapter/readers/cif/CifReader.java  2013-08-17 
02:51:29 UTC (rev 18584)
@@ -533,8 +533,7 @@
         processModulationLoopBlock();
       return;
     }
-    if (str.startsWith("_atom_site_") || str.startsWith("_atom_site.")
-        || (isLigand = str.equals("_chem_comp_atom.comp_id"))) {
+    if (str.startsWith("_atom_site_") || (isLigand = 
str.equals("_chem_comp_atom_comp_id"))) {
       if (!processAtomSiteLoopBlock(isLigand))
         return;
       atomSetCollection.setAtomSetName(thisDataSetName);

Modified: trunk/Jmol/src/org/jmol/awtjs2d/Mouse.java
===================================================================
--- trunk/Jmol/src/org/jmol/awtjs2d/Mouse.java  2013-08-16 16:30:06 UTC (rev 
18583)
+++ trunk/Jmol/src/org/jmol/awtjs2d/Mouse.java  2013-08-17 02:51:29 UTC (rev 
18584)
@@ -119,28 +119,28 @@
       return;
     float[][] t1 = touches[0];
     float[][] t2 = touches[1];
-    float[] t10 = t1[0];
-    float[] t11 = t1[t2.length - 1];
-    float x10 = t10[0];
-    float x11 = t11[0]; 
-    float dx1 = x11 - x10;
-    float y10 = t10[1];
-    float y11 = t11[1]; 
-    float dy1 = y11 - y10;
+    float[] t1first = t1[0];
+    float[] t1last = t1[t2.length - 1];
+    float x1first = t1first[0];
+    float x1last = t1last[0]; 
+    float dx1 = x1last - x1first;
+    float y1first = t1first[1];
+    float y1last = t1last[1]; 
+    float dy1 = y1last - y1first;
     V3 v1 = V3.new3(dx1, dy1, 0);
     float d1 = v1.length();
-    float[] t20 = t2[0];
-    float[] t21 = t2[t2.length - 1];
-    float x20 = t20[0];
-    float x21 = t21[0]; 
-    float dx2 = x21 - x20;
-    float y20 = t20[1];
-    float y21 = t21[1]; 
-    float dy2 = y21 - y20;
+    float[] t2first = t2[0];
+    float[] t2last = t2[t2.length - 1];
+    float x2first = t2first[0];
+    float x2last = t2last[0]; 
+    float dx2 = x2last - x2first;
+    float y2first = t2first[1];
+    float y2last = t2last[1]; 
+    float dy2 = y2last - y2first;
     V3 v2 = V3.new3(dx2, dy2, 0);    
     float d2 = v2.length();
     // rooted finger --> zoom (at this position, perhaps?)
-    if (d1 < 3 || d2 < 3)
+    if (d1 < 1 || d2 < 1)
       return;
     v1.normalize();
     v2.normalize();
@@ -150,13 +150,13 @@
     if (cos12 > 0.8) {
       // two co-aligned motions -- translate
       // just use finger 1, last move
-      int deltaX = (int) (x11 - t1[t1.length - 2][0]); 
-      int deltaY = (int) (y11 - t1[t1.length - 2][1]); 
+      int deltaX = (int) (x1last - t1[t1.length - 2][0]); 
+      int deltaY = (int) (y1last - t1[t1.length - 2][1]); 
       viewer.translateXYBy(deltaX, deltaY);
     } else if (cos12 < -0.8) {
       // two classic zoom motions -- zoom
-      v1 = V3.new3(x20 - x10, y20 - y10, 0);
-      v2 = V3.new3(x21 - x11, y21 - y11, 0);
+      v1 = V3.new3(x2first - x1first, y2first - y1first, 0);
+      v2 = V3.new3(x2last - x1last, y2last - y1last, 0);
       float dx = v2.length() - v1.length();
       wheeled(System.currentTimeMillis(), dx < 0 ? -1 : 1, Binding.WHEEL);
     }

Modified: trunk/Jmol/src/org/jmol/util/Escape.java
===================================================================
--- trunk/Jmol/src/org/jmol/util/Escape.java    2013-08-16 16:30:06 UTC (rev 
18583)
+++ trunk/Jmol/src/org/jmol/util/Escape.java    2013-08-17 02:51:29 UTC (rev 
18584)
@@ -548,7 +548,7 @@
           if (Character.isDigit(ch)) {
             if (iThis < 0)
               iThis = 0;
-            iThis = (iThis << 3) + (iThis << 1) + (ch - '0');
+            iThis = (iThis * 10) + (ch - 48);
           }
         }
       }
@@ -1014,12 +1014,12 @@
   }
   
   public static int getHexitValue(char ch) {
-    if (ch >= '0' && ch <= '9')
-      return ch - '0';
-    else if (ch >= 'a' && ch <= 'f')
-      return 10 + ch - 'a';
-    else if (ch >= 'A' && ch <= 'F')
-      return 10 + ch - 'A';
+    if (ch >= 48 && ch <= 57)
+      return ch - 48;
+    else if (ch >= 97 && ch <= 102)
+      return 10 + ch - 97;
+    else if (ch >= 65 && ch <= 70)
+      return 10 + ch - 65;
     else
       return -1;
   }

Modified: trunk/Jmol/src/org/jmol/util/Parser.java
===================================================================
--- trunk/Jmol/src/org/jmol/util/Parser.java    2013-08-16 16:30:06 UTC (rev 
18583)
+++ trunk/Jmol/src/org/jmol/util/Parser.java    2013-08-17 02:51:29 UTC (rev 
18584)
@@ -369,7 +369,7 @@
     0.000000001f
     };
 
-  private final static float[] tensScale = { 10, 100, 1000, 10000, 100000, 
1000000 };
+  private final static float[] tensScale = { 10f, 100f, 1000f, 10000f, 
100000f, 1000000f };
 
   /**
    * A float parser that is 30% faster than Float.parseFloat(x) and also 
accepts
@@ -395,35 +395,41 @@
       ++ich;
       negative = true;
     }
-    char ch = 0;
-    int ival = 0;
-    while (ich < ichMax && (ch = str.charAt(ich)) >= '0' && ch <= '9') {
-      ival = (ival << 3) + (ival << 1) + (ch - '0');
+    // looks crazy, but if we don't do this, Google Closure Compiler will 
+    // write code that Safari will misinterpret in a VERY nasty way -- 
+    // getting totally confused as to long integers and double values
+    int ch = 0;
+    float ival = 0f;
+    float ival2 = 0f;
+    while (ich < ichMax && (ch = str.charAt(ich)) >= 48 && ch <= 57) {
+      ival = (ival * 10f) + (ch - 48)*1f;
       ++ich;
       digitSeen = true;
     }
     boolean isDecimal = false;
-    int ival2 = 0;
     int iscale = 0;
     int nzero = (ival == 0 ? -1 : 0);
     if (ch == '.') {
       isDecimal = true;
-      while (++ich < ichMax && (ch = str.charAt(ich)) >= '0' && ch <= '9') {
+      while (++ich < ichMax && (ch = str.charAt(ich)) >= 48 && ch <= 57) {
         digitSeen = true;
         if (nzero < 0) {
-          if (ch == '0') { 
+          if (ch == 48) { 
             nzero--;
             continue;
           }
           nzero = -nzero;
         } 
         if (iscale  < decimalScale.length) {
-          ival2 = (ival2 << 3) + (ival2 << 1) + (ch - '0');
+          ival2 = (ival2 * 10f) + (ch - 48)*1f;
           iscale++;
         }
       }
     }
     float value;
+    
+    // Safari breaks here intermittently converting integers to floats 
+    
     if (!digitSeen) {
       value = Float.NaN;
     } else if (ival2 > 0) {
@@ -461,6 +467,8 @@
     } else {
       next[0] = ich; // the exponent code finds its own ichNextParse
     }
+    // believe it or not, Safari reports the long-equivalent of the 
+    // float value here, then later the float value, after no operation!
     if (negative)
       value = -value;
     if (value == Float.POSITIVE_INFINITY)
@@ -550,12 +558,12 @@
     while (ich < ichMax && isWhiteSpace(str, ich))
       ++ich;
     boolean negative = false;
-    if (ich < ichMax && str.charAt(ich) == '-') {
+    if (ich < ichMax && str.charAt(ich) == 45) { //"-"
       negative = true;
       ++ich;
     }
-    while (ich < ichMax && (ch = str.charAt(ich)) >= '0' && ch <= '9') {
-      value = (value << 3) + (value << 1) + (ch - '0');
+    while (ich < ichMax && (ch = str.charAt(ich)) >= 48 && ch <= 57) {
+      value = value * 10 + (ch - 48);
       digitSeen = true;
       ++ich;
     }
@@ -739,4 +747,13 @@
       return Float.parseFloat(s);
     }
   }
+  
+  static {
+    long x = System.currentTimeMillis();
+    int j;
+    for(int i = 0; i < 1000000; i++)
+      j = 35 * 3;
+    System.out.println(System.currentTimeMillis() - x);
+    System.out.println("OK");
+  }
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to