[geos-commits] r2801 - trunk/source/linearref

svn_geos at osgeo.org svn_geos at osgeo.org
Sat Dec 5 15:30:56 EST 2009


Author: mloskot
Date: 2009-12-05 15:30:54 -0500 (Sat, 05 Dec 2009)
New Revision: 2801

Modified:
   trunk/source/linearref/ExtractLineByLocation.cpp
Log:
small cleanup

Modified: trunk/source/linearref/ExtractLineByLocation.cpp
===================================================================
--- trunk/source/linearref/ExtractLineByLocation.cpp	2009-12-05 20:23:15 UTC (rev 2800)
+++ trunk/source/linearref/ExtractLineByLocation.cpp	2009-12-05 20:30:54 UTC (rev 2801)
@@ -91,29 +91,46 @@
 	CoordinateSequence* coordinates = line->getCoordinates();
 	CoordinateArraySequence newCoordinateArray;
 
+    const unsigned int indexStep = 1;
 	unsigned int startSegmentIndex = start.getSegmentIndex();
+    
 	if (start.getSegmentFraction() > 0.0)
-		startSegmentIndex += 1;
-	unsigned int lastSegmentIndex = end.getSegmentIndex();
+    {
+		startSegmentIndex += indexStep;
+    }
+	
+    unsigned int lastSegmentIndex = end.getSegmentIndex();
 	if (end.getSegmentFraction() == 1.0)
-		lastSegmentIndex += 1;
+    {
+		lastSegmentIndex += indexStep;
+    }
+
 	if (lastSegmentIndex >= coordinates->size())
-		lastSegmentIndex = coordinates->size() - 1;
-	// not needed - LinearLocation values should always be correct
-	//Assert.isTrue(end.getSegmentFraction() <= 1.0, "invalid segment fraction value");
+    {
+        assert(coordinates->size() > 0);
+        lastSegmentIndex = coordinates->size() - indexStep;
+    }
 
 	if (! start.isVertex())
+    {
 		newCoordinateArray.add(start.getCoordinate(line));
+    }
+
 	for (unsigned int i = startSegmentIndex; i <= lastSegmentIndex; i++)
 	{
 		newCoordinateArray.add((*coordinates)[i]);
 	}
+
 	if (! end.isVertex())
+    {
 		newCoordinateArray.add(end.getCoordinate(line));
+    }
 
 	// ensure there is at least one coordinate in the result
 	if (newCoordinateArray.size() == 0)
+    {
 		newCoordinateArray.add(start.getCoordinate(line));
+    }
 
 	/**
 	 * Ensure there is enough coordinates to build a valid line.



More information about the geos-commits mailing list