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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Sep 20 07:59:09 PDT 2013


Author: mmetz
Date: 2013-09-20 07:59:09 -0700 (Fri, 20 Sep 2013)
New Revision: 57764

Modified:
   grass/trunk/lib/vector/diglib/poly.c
Log:
diglib: partially revert r36395, line integral is more robust than surveyor's formula

Modified: grass/trunk/lib/vector/diglib/poly.c
===================================================================
--- grass/trunk/lib/vector/diglib/poly.c	2013-09-20 13:00:10 UTC (rev 57763)
+++ grass/trunk/lib/vector/diglib/poly.c	2013-09-20 14:59:09 UTC (rev 57764)
@@ -94,36 +94,25 @@
  *
  * points must be closed polygon with first point = last point
  *
- * formula modified from:
- * Sunday, Daniel. 2002. Fast Polygon Area and Newell Normal Computation.
- * Journal of Graphics Tools; 7(2):9-13.
- *
  * returns signed area, positive for clockwise, negative for
  * counterclockwise, 0 for degenerate
  */
 int dig_find_area_poly(struct line_pnts *Points, double *totalarea)
 {
-    int i, n = Points->n_points - 1;
+    int i;
     double *x, *y;
     double tot_area;
 
-    /* TODO: check if results are still accurate without pruning *Points first
-     * consecutive duplicate vertices should in theory result in wrong area size */
-
     x = Points->x;
     y = Points->y;
 
-    /* first point 0 == point n */
-    tot_area = y[0] * (x[1] - x[n - 1]);
-    for (i = 1; i < n; i++) {
-        tot_area += y[i] * (x[i + 1] - x[i - 1]);
-    }
-
-    /* tot_area = 0.0;
+    /* line integral: *Points do not need to be pruned */
+    /* surveyor's formula is more common, but more prone to
+     * fp precision limit errors, and *Points would need to be pruned */
+    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);



More information about the grass-commit mailing list