[xiph-commits] r12239 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Mon Dec 25 13:13:32 PST 2006


Author: xiphmont
Date: 2006-12-25 13:13:31 -0800 (Mon, 25 Dec 2006)
New Revision: 12239

Modified:
   trunk/sushivision/scale.c
Log:
Do a little bug cleanup for inverted scales... a few more to go



Modified: trunk/sushivision/scale.c
===================================================================
--- trunk/sushivision/scale.c	2006-12-25 20:22:50 UTC (rev 12238)
+++ trunk/sushivision/scale.c	2006-12-25 21:13:31 UTC (rev 12239)
@@ -234,6 +234,7 @@
   int place = 0;
   int step = 1;
   long long first;
+  int neg = (lowpoint>highpoint?-1:1);
 
   ret.lo = lowpoint;
   ret.hi = highpoint;
@@ -268,7 +269,9 @@
     range *= .5;
   }
 
+  step *= neg;
   ret.step_val = step;
+
   if(pixels == 0. || range == 0.)
     ret.step_pixel = max_spacing;
   else
@@ -276,20 +279,34 @@
   ret.m = pow(10,place);
   first = (long long)(lowpoint/ret.m)/step*step;
 
-  if(LLONG_MAX * ret.m < lowpoint){
-    ret.m = 0;
-    return ret;
+  if(neg){
+    if(LLONG_MAX * ret.m < highpoint){
+      ret.m = 0;
+      return ret;
+    }
+  }else{
+    if(LLONG_MAX * ret.m < lowpoint){
+      ret.m = 0;
+      return ret;
+    }
   }
 
-  while(first * ret.m < lowpoint)
+  while(first * ret.m * neg < lowpoint*neg)
     first += step;
 
-  if(LLONG_MIN * ret.m > highpoint){
-    ret.m = 0;
-    return ret;
+  if(neg){
+    if(LLONG_MIN * ret.m > lowpoint){
+      ret.m = 0;
+      return ret;
+    }
+  }else{
+    if(LLONG_MIN * ret.m > highpoint){
+      ret.m = 0;
+      return ret;
+    }
   }
 
-  while(first * ret.m > highpoint)
+  while(first * ret.m * neg > highpoint*neg)
     first -= step;
 
   ret.first_val = first;



More information about the commits mailing list