Browse Source

store stroked symbol coords as double not int to avoid some rounding wiggle

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57021 15284696-431f-4ddb-bdfa-cd5b030d7da7
Hamish Bowman 11 years ago
parent
commit
8accf26b3c
3 changed files with 11 additions and 13 deletions
  1. 1 1
      include/symbol.h
  2. 1 1
      lib/symbol/read.c
  3. 9 11
      lib/symbol/stroke.c

+ 1 - 1
include/symbol.h

@@ -51,7 +51,7 @@ typedef struct
     int count, alloc;		/* number of elements */
     SYMBEL **elem;		/* array of elements */
     int scount, salloc;		/* number of points in stroked version */
-    int *sx, *sy;		/* coordinates in stroked version */
+    double *sx, *sy;		/* coordinates in stroked version */
 } SYMBCHAIN;
 
 /* part */

+ 1 - 1
lib/symbol/read.c

@@ -1,4 +1,3 @@
-
 /****************************************************************************
 *
 * MODULE:       Symbol library 
@@ -14,6 +13,7 @@
 *   	    	for details.
 *
 *****************************************************************************/
+
 #include <stdlib.h>
 #include <string.h>
 #include <dirent.h>

+ 9 - 11
lib/symbol/stroke.c

@@ -1,4 +1,3 @@
-
 /****************************************************************************
 *
 * MODULE:       Symbol library 
@@ -14,6 +13,7 @@
 *   	    	for details.
 *
 *****************************************************************************/
+
 #include <stdlib.h>
 #include <math.h>
 #include <grass/gis.h>
@@ -21,16 +21,14 @@
 
 #define PI M_PI
 
-#define round(x) ((int) floor(0.5 + (x)))
-
 
-void add_coor(SYMBCHAIN *chain, int x, int y)
+void add_coor(SYMBCHAIN *chain, double x, double y)
 {
-    G_debug(5, "    add_coor %d, %d", x, y);
+    G_debug(5, "    add_coor %f, %f", x, y);
     if (chain->scount == chain->salloc) {
 	chain->salloc += 10;
-	chain->sx = (int *)G_realloc(chain->sx, chain->salloc * sizeof(int));
-	chain->sy = (int *)G_realloc(chain->sy, chain->salloc * sizeof(int));
+	chain->sx = (double *)G_realloc(chain->sx, chain->salloc * sizeof(double));
+	chain->sy = (double *)G_realloc(chain->sy, chain->salloc * sizeof(double));
     }
     chain->sx[chain->scount] = x;
     chain->sy[chain->scount] = y;
@@ -68,7 +66,7 @@ int stroke_chain(SYMBPART *part, int ch, double s, double rotation)
 		if (rotation != 0.0)
 		    G_rotate_around_point(0, 0, &x, &y, rotation);
 
-		add_coor(chain, round(x), round(y));
+		add_coor(chain, x, y);
 		if (first) {
 		    x0 = x;
 		    y0 = y;
@@ -101,7 +99,7 @@ int stroke_chain(SYMBPART *part, int ch, double s, double rotation)
 		    if (rotation != 0.0)
 			G_rotate_around_point(0, 0, &x, &y, rotation);
 
-		    add_coor(chain, round(x), round(y));
+		    add_coor(chain, x, y);
 		    if (first) {
 			x0 = x;
 			y0 = y;
@@ -123,7 +121,7 @@ int stroke_chain(SYMBPART *part, int ch, double s, double rotation)
 		    if (rotation != 0.0)
 			G_rotate_around_point(0, 0, &x, &y, rotation);
 
-		    add_coor(chain, round(x), round(y));
+		    add_coor(chain, x, y);
 		    if (first) {
 			x0 = x;
 			y0 = y;
@@ -140,7 +138,7 @@ int stroke_chain(SYMBPART *part, int ch, double s, double rotation)
 	}
     }
     if (part->type == S_POLYGON) {
-	add_coor(chain, round(x0), round(y0));	/* Close ring */
+	add_coor(chain, x0, y0);	/* Close ring */
     }
 
     return 0;