浏览代码

diglib: partially revert https://trac.osgeo.org/grass/changeset/36395, line integral is more robust than surveyor's formula

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57764 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 11 年之前
父节点
当前提交
d780df6705
共有 1 个文件被更改,包括 6 次插入17 次删除
  1. 6 17
      lib/vector/diglib/poly.c

+ 6 - 17
lib/vector/diglib/poly.c

@@ -94,36 +94,25 @@ int dig_get_poly_points(int n_lines, struct line_pnts **LPoints,
  *
  * 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);