[geos-commits] r2681 - trunk/source/algorithm/distance

svn_geos at osgeo.org svn_geos at osgeo.org
Sat Oct 17 10:35:20 EDT 2009


Author: strk
Date: 2009-10-17 10:35:20 -0400 (Sat, 17 Oct 2009)
New Revision: 2681

Modified:
   trunk/source/algorithm/distance/DistanceToPoint.cpp
Log:
Half the calls to the virtual CoordinateSequence::getAt when computing line distances


Modified: trunk/source/algorithm/distance/DistanceToPoint.cpp
===================================================================
--- trunk/source/algorithm/distance/DistanceToPoint.cpp	2009-10-17 13:40:25 UTC (rev 2680)
+++ trunk/source/algorithm/distance/DistanceToPoint.cpp	2009-10-17 14:35:20 UTC (rev 2681)
@@ -73,16 +73,22 @@
 	const CoordinateSequence* coordsRO = line.getCoordinatesRO();
 	const CoordinateSequence& coords = *coordsRO;
 
+	size_t npts = coords.size();
+	if ( ! npts ) return; // can this ever be ?
+
 	LineSegment tempSegment;
 	Coordinate closestPt;
-	for (size_t i=0, n=coords.size()-1; i<n; ++i)
+
+	Coordinate* segPts[2] = { &(tempSegment.p0), &(tempSegment.p1) };
+	tempSegment.p0 = coords.getAt(0);
+	for (size_t i=1; i<npts; ++i)
 	{
+		*(segPts[i%2]) = coords.getAt(i);
+
 		// this is somewhat inefficient - could do better
-		tempSegment.setCoordinates(coords[i], coords[i + 1]);
 		tempSegment.closestPoint(pt, closestPt);
 		ptDist.setMinimum(closestPt, pt);
 	}
-
 }
 
 /* public static */



More information about the geos-commits mailing list