[GRASS-SVN] r38380 - grass/trunk/lib/vector/diglib

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jul 13 02:57:23 EDT 2009


Author: mmetz
Date: 2009-07-13 02:57:23 -0400 (Mon, 13 Jul 2009)
New Revision: 38380

Modified:
   grass/trunk/lib/vector/diglib/poly.c
Log:
topo building algorithm update

Modified: grass/trunk/lib/vector/diglib/poly.c
===================================================================
--- grass/trunk/lib/vector/diglib/poly.c	2009-07-13 06:51:45 UTC (rev 38379)
+++ grass/trunk/lib/vector/diglib/poly.c	2009-07-13 06:57:23 UTC (rev 38380)
@@ -120,6 +120,11 @@
         tot_area += y[i] * (x[i + 1] - x[i - 1]);
     }
 
+    /* tot_area = 0.0;
+    for (i = 1; i < Points->n_points; i++) {
+	tot_area += (x[i] - x[i - 1]) * (y[i] + y[i - 1]);
+    } */
+
     *totalarea = 0.5 * tot_area;
 
     return (0);
@@ -127,7 +132,9 @@
 
 /*
  * find orientation of polygon (clockwise or counterclockwise)
- * faster than signed area for > 4 vertices
+ * in theory faster than signed area for > 4 vertices, but is not robust
+ * against special cases
+ * use dog_find_area_poly instead
  *
  * points must be closed polygon with first point = last point
  *
@@ -135,8 +142,8 @@
  * (C) 2000 softSurfer (www.softsurfer.com)
  * (C) 2006 Refractions Research Inc.
  *
- * and now copes with partially collapsed boundaries
- * the code is long but fast
+ * copes with partially collapsed boundaries and 8-shaped isles
+ * the code is long and not much faster than dig_find_area_poly
  * it can be written much shorter, but that comes with speed penalty
  *
  * returns orientation, positive for CW, negative for CCW, 0 for degenerate
@@ -157,6 +164,11 @@
 	else if (y[pnext] == y[pcur]) {    /* just as high */
 	    if (x[pnext] > x[pcur])   	   /* but to the right */
 		continue;
+	    if (x[pnext] == x[pcur]) {   /* duplicate point, self-intersecting polygon ? */
+		pprev = (pcur == 0 ? lastpoint - 1 : pcur - 1);
+		if (y[pnext - 1] < y[pprev])
+		    continue;
+	    }
 	}
 	pcur = pnext;          /* a new leftmost highest vertex */
     }
@@ -198,6 +210,11 @@
 	else if (y[pnext] == y[pcur]) {    /* just as high */
 	    if (x[pnext] < x[pcur])   	/* but to the left */
 		continue;
+	    if (x[pnext] == x[pcur]) {   /* duplicate point, self-intersecting polygon ? */
+		pprev = (pcur == 0 ? lastpoint - 1 : pcur - 1);
+		if (y[pnext - 1] < y[pprev])
+		    continue;
+	    }
 	}
 	pcur = pnext;          /* a new rightmost highest vertex */
     }
@@ -239,6 +256,11 @@
 	else if (y[pnext] == y[pcur]) {    /* just as low */
 	    if (x[pnext] > x[pcur])   	/* but to the right */
 		continue;
+	    if (x[pnext] == x[pcur]) {   /* duplicate point, self-intersecting polygon ? */
+		pprev = (pcur == 0 ? lastpoint - 1 : pcur - 1);
+		if (y[pnext - 1] > y[pprev])
+		    continue;
+	    }
 	}
 	pcur = pnext;          /* a new leftmost lowest vertex */
     }
@@ -280,6 +302,11 @@
 	else if (y[pnext] == y[pcur]) {    /* just as low */
 	    if (x[pnext] < x[pcur])   	/* but to the left */
 		continue;
+	    if (x[pnext] == x[pcur]) {   /* duplicate point, self-intersecting polygon ? */
+		pprev = (pcur == 0 ? lastpoint - 1 : pcur - 1);
+		if (y[pnext - 1] > y[pprev])
+		    continue;
+	    }
 	}
 	pcur = pnext;          /* a new rightmost lowest vertex */
     }



More information about the grass-commit mailing list