浏览代码

fix GRASS_EPSILON usage

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@52885 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 12 年之前
父节点
当前提交
29b6f4a80d
共有 1 个文件被更改,包括 14 次插入3 次删除
  1. 14 3
      lib/raster/color_write.c

+ 14 - 3
lib/raster/color_write.c

@@ -246,10 +246,16 @@ static void format_min(char *str, double dval)
     double dtmp;
     double dtmp;
 
 
     sprintf(str, "%.15g", dval);
     sprintf(str, "%.15g", dval);
+    /* Note that G_trim_decimal() does not trim e.g. 1.0000000e-20 */
     G_trim_decimal(str);
     G_trim_decimal(str);
+
     sscanf(str, "%lf", &dtmp);
     sscanf(str, "%lf", &dtmp);
-    if (dtmp != dval) {  /* if  no zeros after decimal point were trimmed */
-	sprintf(str, "%.15g", dval - GRASS_EPSILON);
+    if (dtmp != dval) {  /* if no zeros after decimal point were trimmed */
+	/* lower dval by fraction of GRASS_EPSILON */
+	if (dval > 0)
+	    sprintf(str, "%.15g", dval * (1 - GRASS_EPSILON));
+	else
+	    sprintf(str, "%.15g", dval * (1 + GRASS_EPSILON));
     }
     }
 }
 }
 
 
@@ -259,9 +265,14 @@ static void format_max(char *str, double dval)
     double dtmp;
     double dtmp;
 
 
     sprintf(str, "%.15g", dval);
     sprintf(str, "%.15g", dval);
+    /* Note that G_trim_decimal() does not trim e.g. 1.0000000e-20 */
     G_trim_decimal(str);
     G_trim_decimal(str);
     sscanf(str, "%lf", &dtmp);
     sscanf(str, "%lf", &dtmp);
     if (dtmp != dval) {  /* if  no zeros after decimal point were trimmed */
     if (dtmp != dval) {  /* if  no zeros after decimal point were trimmed */
-	sprintf(str, "%.15g", dval + GRASS_EPSILON);
+	/* increase dval by fraction of GRASS_EPSILON */
+	if (dval > 0)
+	    sprintf(str, "%.15g", dval * (1 + GRASS_EPSILON));
+	else
+	    sprintf(str, "%.15g", dval * (1 - GRASS_EPSILON));
     }
     }
 }
 }