[GRASS-SVN] r61851 - in grass/trunk/lib/gis: . colors

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 10 12:14:55 PDT 2014


Author: mmetz
Date: 2014-09-10 12:14:55 -0700 (Wed, 10 Sep 2014)
New Revision: 61851

Modified:
   grass/trunk/lib/gis/colors/ndvi
   grass/trunk/lib/gis/flate.c
   grass/trunk/lib/gis/getl.c
   grass/trunk/lib/gis/gisinit.c
   grass/trunk/lib/gis/intersect.c
   grass/trunk/lib/gis/ll_scan.c
   grass/trunk/lib/gis/wind_format.c
Log:
libgis: fix G_intersect_line_segments()

Modified: grass/trunk/lib/gis/colors/ndvi
===================================================================
--- grass/trunk/lib/gis/colors/ndvi	2014-09-10 18:46:24 UTC (rev 61850)
+++ grass/trunk/lib/gis/colors/ndvi	2014-09-10 19:14:55 UTC (rev 61851)
@@ -1,21 +1,12 @@
--1.000   5  24  82
--0.300   5  24  82
--0.180 255 255 255
- 0.000 255 255 255
- 0.025 206 197 180
- 0.075 191 163 124
- 0.125 179 174  96
- 0.150 163 181  80
- 0.175 144 170  60
- 0.233 166 195  29
- 0.266 135 183   3
- 0.333 121 175   1
- 0.366 101 163   0
- 0.433  78 151   0
- 0.466  43 132   4
- 0.550   0 114   0
- 0.650   0  90   1
- 0.750   0  73   0
- 0.850   0  56   0
- 0.950   0  31   0
- 1.000   0   0   0
+-200 white
+-1.0000 white
+-0.3000 0:0:100 
+-0.2000 205:193:173
+ 0.0000 150:150:150
+ 0.1000 120:100:51
+ 0.3000 120:200:100
+ 0.4000 28:144:3
+ 0.6000 6:55:0
+ 0.8000 10:30:25
+ 1.0000 100:0:60
+ 200 100:0:60

Modified: grass/trunk/lib/gis/flate.c
===================================================================
--- grass/trunk/lib/gis/flate.c	2014-09-10 18:46:24 UTC (rev 61850)
+++ grass/trunk/lib/gis/flate.c	2014-09-10 19:14:55 UTC (rev 61851)
@@ -333,7 +333,7 @@
     /* zlib default: Z_DEFAULT_COMPRESSION = -1, equivalent to 6 
      * as used here, 1 gives the best compromise between speed and compression */
     err = deflateInit(&c_stream,
-                      (G__.compression_level < -1 || G__.compression_level > 9) 
+                      (G__.compression_level < -1 || G__.compression_level > 9)
 		      ? 1 : G__.compression_level);
 
     /* If there was an error initializing, return -1 */

Modified: grass/trunk/lib/gis/getl.c
===================================================================
--- grass/trunk/lib/gis/getl.c	2014-09-10 18:46:24 UTC (rev 61850)
+++ grass/trunk/lib/gis/getl.c	2014-09-10 19:14:55 UTC (rev 61851)
@@ -55,7 +55,7 @@
  * must be allocated for the string buffer.
  *
  * \param buf: string buffer to receive read data, at least <i>n</i> must be allocated
- * \param n: maximum number of bytes to read
+ * \param n: number of bytes allocated for buf, at most <i>n - 1</i> are read
  * \param fd: file descriptor structure
  *
  * \return 1 on success
@@ -67,7 +67,7 @@
     int c;
     int ret = 1;
 
-    while (i < n - 1) {
+    while (i < n) {
 	c = fgetc(fd);
 
 	if (c == EOF) {
@@ -88,12 +88,20 @@
 	    }
 	    break;
 	}
+	
+	if (i < n - 1) {
+	    buf[i] = c;
+	}
 
-	buf[i] = c;
-
 	i++;
     }
-    buf[i] = '\0';
 
+    if (i < n)
+	buf[i] = '\0';
+    else {
+	buf[n - 1] = '\0';
+	ret = -1;
+    }
+
     return ret;
 }

Modified: grass/trunk/lib/gis/gisinit.c
===================================================================
--- grass/trunk/lib/gis/gisinit.c	2014-09-10 18:46:24 UTC (rev 61850)
+++ grass/trunk/lib/gis/gisinit.c	2014-09-10 19:14:55 UTC (rev 61851)
@@ -117,8 +117,13 @@
     /* byte order */
     G__.little_endian = G_is_little_endian();
 
+    /* zlib compression level for raster maps */
     zlib = getenv("GRASS_ZLIB_LEVEL");
-    G__.compression_level = (zlib && *zlib && isdigit(*zlib)) ? atoi(zlib) : -2;
+    G__.compression_level = (zlib && *zlib) ? atoi(zlib) : 1;
+    if (zlib && G__.compression_level == 0) {
+	G_warning(_("Raster compression disabled with %s=%s"), 
+		"GRASS_ZLIB_LEVEL", zlib);
+    }
 
     initialized = 1;
 

Modified: grass/trunk/lib/gis/intersect.c
===================================================================
--- grass/trunk/lib/gis/intersect.c	2014-09-10 18:46:24 UTC (rev 61850)
+++ grass/trunk/lib/gis/intersect.c	2014-09-10 19:14:55 UTC (rev 61851)
@@ -75,7 +75,7 @@
 #define D1 ((bx1-ax1)*(by1-by2) - (by1-ay1)*(bx1-bx2))
 #define D2 ((ax2-ax1)*(by1-ay1) - (ay2-ay1)*(bx1-ax1))
 
-#define SWAP(x,y) {int t; t=x; x=y; y=t;}
+#define SWAP(x,y) {double t; t=x; x=y; y=t;}
 
 int G_intersect_line_segments(double ax1, double ay1, double ax2, double ay2,
 			      double bx1, double by1, double bx2, double by2,
@@ -83,6 +83,16 @@
 {
     double d;
 
+    if (ax1 > ax2 || (ax1 == ax2 && ay1 > ay2)) {
+	SWAP(ax1, ax2)
+	SWAP(ay1, ay2)
+    }
+
+    if (bx1 > bx2 || (bx1 == bx2 && by1 > by2)) {
+	SWAP(bx1, bx2)
+	SWAP(by1, by2)
+    }
+
     d = D;
 
     if (d) {			/* lines are not parallel */
@@ -94,31 +104,74 @@
 	return (*ra >= 0.0 && *ra <= 1.0 && *rb >= 0.0 && *rb <= 1.0);
     }
 
-    if (D1 || D2)
-	return -1;		/* lines are parallel, not colinear */
+    /* lines are parallel */
+    if (D1 || D2) {
+	return 0;
+    }
 
-    if (ax1 > ax2) {
-	SWAP(ax1, ax2)
+    /* segments are colinear. check for overlap */
+
+    /* Collinear vertical */
+    if (ax1 == ax2) {
+	if (ay1 > by2)
+	    return 0;
+	if (ay2 < by1)
+	    return 0;
+
+	/* there is overlap */
+
+	if (ay1 == by2) {
+	    *x = ax1;
+	    *y = ay1;
+	    return 1;		/* endpoints only */
+	}
+	if (ay2 == by1) {
+	    *x = ax2;
+	    *y = ay2;
+	    return 1;		/* endpoints only */
+	}
+
+	/* overlap, no single intersection point */
+	if (ay1 > by1 && ay1 < by2) {
+	    *x = ax1;
+	    *y = ay1;
+	}
+	else {
+	    *x = ax2;
+	    *y = ay2;
+	}
+	return -1;
     }
-    if (bx1 > bx2) {
-	SWAP(bx1, bx2)
-    }
-    if (ax1 > bx2)
+    else {
+	if (ax1 > bx2)
+	    return 0;
+	if (ax2 < bx1)
+	    return 0;
+
+	/* there is overlap */
+
+	if (ax1 == bx2) {
+	    *x = ax1;
+	    *y = ay1;
+	    return 1;		/* endpoints only */
+	}
+	if (ax2 == bx1) {
+	    *x = ax2;
+	    *y = ay2;
+	    return 1;		/* endpoints only */
+	}
+	
+	/* overlap, no single intersection point */
+	if (ax1 > bx1 && ax1 < bx2) {
+	    *x = ax1;
+	    *y = ay1;
+	}
+	else {
+	    *x = ax2;
+	    *y = ay2;
+	}
 	return -1;
-    if (ax2 < bx1)
-	return -1;
-
-    /* there is overlap */
-    if (ax1 == bx2) {
-	*x = ax1;
-	*y = ay1;
-	return 1;		/* at endpoints only */
     }
-    if (ax2 == bx1) {
-	*x = ax2;
-	*y = ay2;
-	return 1;		/* at endpoints only */
-    }
 
-    return 2;			/* colinear with overlap on an interval, not just a single point */
+    return 0; /* should not be reached */
 }

Modified: grass/trunk/lib/gis/ll_scan.c
===================================================================
--- grass/trunk/lib/gis/ll_scan.c	2014-09-10 18:46:24 UTC (rev 61850)
+++ grass/trunk/lib/gis/ll_scan.c	2014-09-10 19:14:55 UTC (rev 61851)
@@ -48,7 +48,7 @@
 
 int G_lon_scan(const char *buf, double *lon)
 {
-    return scan_ll(buf, "we", lon, 180);
+    return scan_ll(buf, "we", lon, 360);
 }
 
 int G_llres_scan(const char *buf, double *res)

Modified: grass/trunk/lib/gis/wind_format.c
===================================================================
--- grass/trunk/lib/gis/wind_format.c	2014-09-10 18:46:24 UTC (rev 61850)
+++ grass/trunk/lib/gis/wind_format.c	2014-09-10 19:14:55 UTC (rev 61851)
@@ -87,7 +87,7 @@
     if (full_prec)
 	sprintf(buf, "%.15g", value);
     else
-	sprintf(buf, "%.8f", value);
+	sprintf(buf, "%.8g", value);
 
     G_trim_decimal(buf);
 }



More information about the grass-commit mailing list