[GRASS-SVN] r34731 - grass/branches/develbranch_6/lib/driver

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 4 21:07:34 EST 2008


Author: glynn
Date: 2008-12-04 21:07:34 -0500 (Thu, 04 Dec 2008)
New Revision: 34731

Modified:
   grass/branches/develbranch_6/lib/driver/Polygon.c
Log:
Fix sub-pixel shifts in polygon rendering


Modified: grass/branches/develbranch_6/lib/driver/Polygon.c
===================================================================
--- grass/branches/develbranch_6/lib/driver/Polygon.c	2008-12-05 02:06:36 UTC (rev 34730)
+++ grass/branches/develbranch_6/lib/driver/Polygon.c	2008-12-05 02:07:34 UTC (rev 34731)
@@ -1,4 +1,5 @@
 #include <stdlib.h>
+#include <math.h>
 #include <grass/gis.h>
 #include "driver.h"
 #include "driverlib.h"
@@ -32,7 +33,7 @@
 	const struct point *p0 = &p[i];
 	const struct point *p1 = &p[i + 1];
 	const struct point *tmp;
-	double fx;
+	double fx, fy;
 	long x;
 
 	if (p0->y == p1->y)
@@ -47,10 +48,11 @@
 	if (p1->y <= y)
 	    continue;
 
-	fx = (double)p1->x * (y - p0->y) + (double)p0->x * (p1->y - y);
+	fy = y + 0.5;
+	fx = (double)p1->x * (fy - p0->y) + (double)p0->x * (p1->y - fy);
 	fx /= p1->y - p0->y;
 	x = fx < -0x7fffffff ? -0x7fffffff :
-	    fx > 0x7fffffff ? 0x7fffffff : (long)fx;
+	    fx > 0x7fffffff ? 0x7fffffff : (long)floor(fx + 0.5);
 
 	if (num_x >= max_x) {
 	    max_x += 20;



More information about the grass-commit mailing list