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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Mar 19 05:30:52 EDT 2009


Author: mmetz
Date: 2009-03-19 05:30:52 -0400 (Thu, 19 Mar 2009)
New Revision: 36416

Modified:
   grass/trunk/lib/vector/diglib/poly.c
Log:
orientation index optimisation

Modified: grass/trunk/lib/vector/diglib/poly.c
===================================================================
--- grass/trunk/lib/vector/diglib/poly.c	2009-03-19 09:25:36 UTC (rev 36415)
+++ grass/trunk/lib/vector/diglib/poly.c	2009-03-19 09:30:52 UTC (rev 36416)
@@ -130,7 +130,7 @@
 double dig_find_poly_orientation(struct line_pnts *Points)
 {
     unsigned int pnext, pprev, pcur = 0;
-    unsigned int npoints = Points->n_points - 1; /* skip last point == first point */
+    unsigned int lastpoint = Points->n_points - 1;
     double *x, *y;
 
     /* first find leftmost highest vertex of the polygon */
@@ -139,7 +139,7 @@
     x = Points->x;
     y = Points->y;
 
-    for (pnext = 1; pnext < npoints; pnext++) {
+    for (pnext = 1; pnext < lastpoint; pnext++) {
 	if (y[pnext] < y[pcur])
 	    continue;
 	else if (y[pnext] == y[pcur]) {    /* just as high */
@@ -150,30 +150,34 @@
     }
 
     /* Points are not pruned, so ... */
-    
+
     /* find next distinct point */
-    pnext = pcur + 1;
+    if (pcur == lastpoint)
+	pnext = 0;
+    else
+	pnext = pcur + 1;
     while (pnext != pcur) {
 	if (x[pcur] != x[pnext] || y[pcur] != y[pnext])
 	    break;
-	pnext++;
-	if (pnext == npoints)
+	if (pnext < lastpoint - 1)
+	    pnext++;
+	else
 	    pnext = 0;
     }
 
     /* find previous distinct point */
     if (pcur == 0)
-	pprev = npoints - 1;
-    else
-	pprev = pcur - 1;
+	pcur = lastpoint;
+    pprev = pcur - 1;
     while (pprev != pcur) {
-	if (pprev == 0)
-	    pprev = npoints;
 	if (x[pcur] != x[pprev] || y[pcur] != y[pprev])
 	    break;
-	pprev--;
+	if (pprev > 1)
+	    pprev--;
+	else
+	    pprev = lastpoint;
     }
-
+    
     /* orientation at vertex pcur == signed area for triangle pprev, pcur, pnext
      * rather use robust determinant of Olivier Devillers? */
     return (x[pnext] - x[pprev]) * (y[pcur] - y[pprev])



More information about the grass-commit mailing list