[xiph-commits] r12274 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Sun Dec 31 13:00:24 PST 2006


Author: xiphmont
Date: 2006-12-31 13:00:22 -0800 (Sun, 31 Dec 2006)
New Revision: 12274

Modified:
   trunk/sushivision/panel-1d.c
   trunk/sushivision/panel-2d.c
   trunk/sushivision/scale.c
Log:
Fix more scaling and scale display bugs.  Resolution is approximately 17-18 sig figs on the scales now, more than that and scale display precision begins to break down.



Modified: trunk/sushivision/panel-1d.c
===================================================================
--- trunk/sushivision/panel-1d.c	2006-12-31 19:32:39 UTC (rev 12273)
+++ trunk/sushivision/panel-1d.c	2006-12-31 21:00:22 UTC (rev 12274)
@@ -150,16 +150,18 @@
   int offset = ilog10(w>h?w:h);
 
   if(plot){
-    int i;
+    int i,depth=0;
     char buffer[320];
     plot_legend_clear(plot);
 
+    if(-p1->vs.decimal_exponent > depth) depth = 3-p1->vs.decimal_exponent;
+
     // add each dimension to the legend
     for(i=0;i<p->dimensions;i++){
       // display decimal precision relative to bracket
-      int depth = del_depth(p->dimension_list[i].d->bracket[0],
-			    p->dimension_list[i].d->bracket[1]) + offset;
-      snprintf(buffer,320,"%s = %.*f",
+      //int depth = del_depth(p->dimension_list[i].d->bracket[0],
+      //		    p->dimension_list[i].d->bracket[1]) + offset;
+      snprintf(buffer,320,"%s = %+.*f",
 	       p->dimension_list[i].d->name,
 	       depth,
 	       p->dimension_list[i].d->val);
@@ -169,16 +171,17 @@
     // linked? add the linked dimension value to the legend
     if(p1->link_x || p1->link_y){
       sushiv_dimension_t *d;
-      int depth;
+      int depth=0;
       if(p1->link_x)
 	d = p1->link_x->subtype->p2->x_d;
       else
 	d = p1->link_y->subtype->p2->y_d;
 
-      // display decimal precision relative to bracket
-      depth = del_depth(d->bracket[0],
-			d->bracket[1]) + offset;
-      snprintf(buffer,320,"%s = %.*f",
+      
+      // add each dimension to the legend
+      // display decimal precision relative to display scales
+      if(3-p1->vs.decimal_exponent > depth) depth = 3-p1->vs.decimal_exponent;
+      snprintf(buffer,320,"%s = %+.*f",
 	       d->name,
 	       depth,
 	       d->val);

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2006-12-31 19:32:39 UTC (rev 12273)
+++ trunk/sushivision/panel-2d.c	2006-12-31 21:00:22 UTC (rev 12274)
@@ -128,14 +128,17 @@
   if(plot){
     int i;
     char buffer[320];
+    int depth = 0;
     plot_legend_clear(plot);
 
     // add each dimension to the legend
+    // display decimal precision relative to display scales
+    if(3-p2->x.decimal_exponent > depth) depth = 3-p2->x.decimal_exponent;
+    if(3-p2->y.decimal_exponent > depth) depth = 3-p2->y.decimal_exponent;
     for(i=0;i<p->dimensions;i++){
-      // display decimal precision relative to bracket
-      int depth = del_depth(p->dimension_list[i].d->bracket[0],
-			    p->dimension_list[i].d->bracket[1]) + offset;
-      snprintf(buffer,320,"%s = %.*f",
+      //int depth = del_depth(p->dimension_list[i].d->bracket[0],
+      //		    p->dimension_list[i].d->bracket[1]) + offset;
+      snprintf(buffer,320,"%s = %+.*f",
 	       p->dimension_list[i].d->name,
 	       depth,
 	       p->dimension_list[i].d->val);

Modified: trunk/sushivision/scale.c
===================================================================
--- trunk/sushivision/scale.c	2006-12-31 19:32:39 UTC (rev 12273)
+++ trunk/sushivision/scale.c	2006-12-31 21:00:22 UTC (rev 12274)
@@ -200,7 +200,7 @@
 /* plot and graph scales */
 
 double scalespace_value(scalespace *s, double pixel){
-  double val = (pixel-s->first_pixel)*s->step_val/s->step_pixel + s->first_val;
+  double val = (double)(pixel-s->first_pixel)*s->step_val/s->step_pixel + s->first_val;
   return val * s->m;
 }
 
@@ -232,26 +232,34 @@
 
 // name is *not* copied
 scalespace scalespace_linear (double lowpoint, double highpoint, int pixels, int max_spacing, char *name){
-  double range = fabs(highpoint - lowpoint);
+  double orange = fabs(highpoint - lowpoint), range;
   scalespace ret;
 
-  int place = 0;
-  int step = 1;
+  int place;
+  int step;
   long long first;
   int neg = (lowpoint>highpoint?-1:1);
 
+  if(pixels<1)pixels=1;
+
   ret.lo = lowpoint;
   ret.hi = highpoint;
   ret.init = 1;
   ret.pixels=pixels;
   ret.legend=name;
 
-  if(range < DBL_MIN*pixels){
-    ret.m = DBL_MIN * pixels;
-    highpoint = lowpoint + ret.m;
+  if(orange < DBL_MIN*pixels){
+    // insufficient to safeguard the int64 first var below all by
+    // itself, but it will keep things on track until later checks
+    orange = DBL_MIN * pixels;
+    highpoint = lowpoint + orange;
   }
 
-  if(range!=0.){
+  while(1){
+    range = orange;
+    place = 0;
+    step = 1;
+
     while(pixels / range < max_spacing){
       place++;
       range *= .1;
@@ -260,39 +268,73 @@
       place--;
       range *= 10;
     }
-  }
+    
+    ret.decimal_exponent = place;
+    
+    if (pixels / (range*.2) <= max_spacing){
+      step *= 5;
+      range *= .2;
+    }
+    if (pixels / (range*.5) <= max_spacing){
+      step *= 2;
+      range *= .5;
+    }
 
-  ret.decimal_exponent = place;
+    step *= neg;
+    ret.step_val = step;
+    
+    if(pixels == 0. || range == 0.)
+      ret.step_pixel = max_spacing;
+    else
+      ret.step_pixel = rint(pixels / range);
+    ret.m = pow(10,place);
+  
+    first = (long long)(lowpoint/ret.m)/step*step;
 
-  if (pixels / (range*.2) <= max_spacing){
-    step *= 5;
-    range *= .2;
-  }
-  if (pixels / (range*.5) <= max_spacing){
-    step *= 2;
-    range *= .5;
-  }
+    if(neg){
+      if(LLONG_MAX * ret.m < highpoint){
+	orange *= 2;
+	continue;
+      }
+    }else{
+      if(LLONG_MAX * ret.m < lowpoint){
+	orange *= 2;
+	continue;
+      }
+    }
 
-  step *= neg;
-  ret.step_val = step;
+    while(first * ret.m * neg < lowpoint*neg)
+      first += step;
+    
+    if(neg){
+      if(LLONG_MIN * ret.m > lowpoint){
+	orange *= 2;
+	continue;
+      }
+    }else{
+      if(LLONG_MIN * ret.m > highpoint){
+	orange *= 2;
+	continue;
+      }
+    }
+    
+    while(first * ret.m * neg > highpoint*neg)
+      first -= step;
+    
+    // make sure the scale display has meaningful sig figs to work with */
+    if( first*128/128 != first ||
+	first*16*ret.m == (first*16 +step)*ret.m ||
+	(first*16+step)*ret.m == (first*16 +step*2)*ret.m){
+      orange*=2;
+      continue;
+    }
 
-  if(pixels == 0. || range == 0.)
-    ret.step_pixel = max_spacing;
-  else
-    ret.step_pixel = rint(pixels / range);
-  ret.m = pow(10,place);
-  first = (long long)(lowpoint/ret.m)/step*step;
+    ret.first_val = first;
+    
+    ret.first_pixel = rint((first - (lowpoint / ret.m)) * ret.step_pixel / ret.step_val);
+    ret.neg = neg;
+    break;
+  }
 
-  while(first * ret.m * neg < lowpoint*neg)
-    first += step;
-
-  while(first * ret.m * neg > highpoint*neg)
-    first -= step;
-
-  ret.first_val = first;
-
-  ret.first_pixel = rint((first - (lowpoint / ret.m)) * ret.step_pixel / ret.step_val);
-  ret.neg = neg;
-
   return ret;
 }



More information about the commits mailing list