[geos-commits] r3544 - trunk/src/algorithm

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Dec 12 05:10:00 EST 2011


Author: strk
Date: 2011-12-12 02:10:00 -0800 (Mon, 12 Dec 2011)
New Revision: 3544

Modified:
   trunk/src/algorithm/CGAlgorithms.cpp
Log:
Apply Shoelace formula for area calculation (#485)

Modified: trunk/src/algorithm/CGAlgorithms.cpp
===================================================================
--- trunk/src/algorithm/CGAlgorithms.cpp	2011-12-12 10:09:32 UTC (rev 3543)
+++ trunk/src/algorithm/CGAlgorithms.cpp	2011-12-12 10:10:00 UTC (rev 3544)
@@ -307,18 +307,20 @@
 
 	if (npts<3) return 0.0;
 
+	Coordinate pp;
+	Coordinate cp = ring->getAt(0);
+	Coordinate np = ring->getAt(1);
+	double x0 = cp.x;
+        np.x -= x0;
 	double sum=0.0;
-	Coordinate p = ring->getAt(0);
-	double bx = p.x;
-	double by = p.y;
 	for (size_t i=1; i<npts; ++i)
 	{
-		ring->getAt(i, p);
-		double cx = p.x;
-		double cy = p.y;
-		sum += (bx+cx) * (cy-by);
-		bx = cx;
-		by = cy;
+		pp.y = cp.y;
+		cp.x = np.x;
+		cp.y = np.y;
+		ring->getAt(i, np);
+                np.x -= x0;
+		sum += cp.x * (np.y - pp.y);
 	}
 	return -sum/2.0;
 }



More information about the geos-commits mailing list