[geos-commits] r3789 - trunk/tests/unit/algorithm

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Mar 11 04:19:59 PDT 2013


Author: strk
Date: 2013-03-11 04:19:59 -0700 (Mon, 11 Mar 2013)
New Revision: 3789

Modified:
   trunk/tests/unit/algorithm/RobustLineIntersectionTest.cpp
Log:
Port new RobustLineIntersection test from JTS

Modified: trunk/tests/unit/algorithm/RobustLineIntersectionTest.cpp
===================================================================
--- trunk/tests/unit/algorithm/RobustLineIntersectionTest.cpp	2013-03-08 18:01:29 UTC (rev 3788)
+++ trunk/tests/unit/algorithm/RobustLineIntersectionTest.cpp	2013-03-11 11:19:59 UTC (rev 3789)
@@ -1,5 +1,5 @@
 // 
-// Ported from JTS junit/algorithm/RobustLineIntersectionTest.java r785
+// Ported from JTS junit/algorithm/RobustLineIntersectionTest.java r788
 
 #include <tut.hpp>
 // geos
@@ -39,11 +39,11 @@
                 return p0.distance(p1) <= distanceTolerance;
         }
 
-	void testIntPoints(const Coordinate& p, const Coordinate& q,
+	void checkIntPoints(const Coordinate& p, const Coordinate& q,
 	                   double distanceTolerance)
         {
                 bool isEqual = equals(p, q, distanceTolerance);
-		ensure("testIntPoints: expected: " + p.toString() + " obtained " + q.toString(), isEqual);
+		ensure("checkIntPoints: expected: " + p.toString() + " obtained " + q.toString(), isEqual);
         }
 
 	/**
@@ -55,7 +55,7 @@
 	 *              must contain at least expectedIntersectionNum
 	 *              elements
 	 */
-	void computeIntersection(const std::vector<Coordinate>& pt,
+	void checkIntersection(const std::vector<Coordinate>& pt,
 	                         int expectedIntersectionNum,
 	                         const std::vector<Coordinate>& intPt,
 	                         double distanceTolerance)
@@ -74,14 +74,14 @@
 		//bool isIntPointsCorrect = true;
 		if (intNum == 1)
 		{
-			testIntPoints(intPt[0], li.getIntersection(0),
+			checkIntPoints(intPt[0], li.getIntersection(0),
 			              distanceTolerance);
 		}
 		else if (intNum == 2)
 		{
-			testIntPoints(intPt[0], li.getIntersection(0),
+			checkIntPoints(intPt[0], li.getIntersection(0),
 			                        distanceTolerance);
-			testIntPoints(intPt[1], li.getIntersection(0),
+			checkIntPoints(intPt[1], li.getIntersection(0),
 			                        distanceTolerance);
 
 			if ( !(
@@ -89,9 +89,9 @@
 			        ||
 		equals(intPt[0],li.getIntersection(1), distanceTolerance) ) )
 			{
-				testIntPoints(intPt[0], li.getIntersection(0),
+				checkIntPoints(intPt[0], li.getIntersection(0),
 				              distanceTolerance);
-				testIntPoints(intPt[0], li.getIntersection(1),
+				checkIntPoints(intPt[0], li.getIntersection(1),
 				              distanceTolerance);
 			}
 
@@ -100,16 +100,16 @@
 				||
 		equals(intPt[1],li.getIntersection(1), distanceTolerance) ) )
 			{
-				testIntPoints(intPt[1], li.getIntersection(0),
+				checkIntPoints(intPt[1], li.getIntersection(0),
 				              distanceTolerance);
-				testIntPoints(intPt[1], li.getIntersection(1),
+				checkIntPoints(intPt[1], li.getIntersection(1),
 				              distanceTolerance);
 			}
 		}
 		//assertTrue("Int Pts not equal", isIntPointsCorrect);
 	}
 
-	void computeIntersection(const std::string& wkt1,
+	void checkIntersection(const std::string& wkt1,
 	                         const std::string& wkt2,
 	                         int expectedIntersectionNum,
 	                         const std::string& expectedWKT,
@@ -142,11 +142,11 @@
 		for (size_t i=0; i<cs->size(); ++i)
 			intPt.push_back(cs->getAt(i));
 
-                computeIntersection(pt, expectedIntersectionNum,
+                checkIntersection(pt, expectedIntersectionNum,
 		                    intPt, distanceTolerance);
         }
 
-	void computeIntersection(const std::string& wkt1,
+	void checkIntersection(const std::string& wkt1,
 	                         const std::string& wkt2,
 	                         int expectedIntersectionNum,
 	                         const std::vector<Coordinate>& intPt,
@@ -171,11 +171,11 @@
 		pt.push_back(l2.getCoordinateN(0));
 		pt.push_back(l2.getCoordinateN(1));
 
-		computeIntersection(pt, expectedIntersectionNum,
+		checkIntersection(pt, expectedIntersectionNum,
 		                    intPt, distanceTolerance);
         }
 
-	void computeIntersectionNone(const std::string& wkt1,
+	void checkIntersectionNone(const std::string& wkt1,
 	                         const std::string& wkt2)
                 // throws ParseException
         {
@@ -198,9 +198,48 @@
 		pt.push_back(l2.getCoordinateN(1));
 
 	  std::vector<Coordinate> intPt;
-		computeIntersection(pt, 0, intPt, 0);
+		checkIntersection(pt, 0, intPt, 0);
         }
 
+  void checkInputNotAltered(const std::string& wkt1, const std::string& wkt2, int scaleFactor)
+  {
+		GeomPtr g1(reader.read(wkt1));
+		GeomPtr g2(reader.read(wkt2));
+
+		LineString* l1ptr = dynamic_cast<LineString*>(g1.get());
+		LineString* l2ptr = dynamic_cast<LineString*>(g2.get());
+
+		ensure(0 != l1ptr);
+		ensure(0 != l2ptr);
+
+		LineString& l1 = *l1ptr;
+		LineString& l2 = *l2ptr;
+
+	  std::vector<Coordinate> pt;
+		pt.push_back(l1.getCoordinateN(0));
+		pt.push_back(l1.getCoordinateN(1));
+		pt.push_back(l2.getCoordinateN(0));
+		pt.push_back(l2.getCoordinateN(1));
+    checkInputNotAltered(pt, scaleFactor);
+  }
+
+  void checkInputNotAltered(const std::vector<Coordinate>& pt, int scaleFactor)
+  {
+    // save input points
+    std::vector<Coordinate> savePt = pt;
+
+		geos::algorithm::LineIntersector li;
+    li.setPrecisionModel(new PrecisionModel(scaleFactor));
+    li.computeIntersection(pt[0], pt[1], pt[2], pt[3]);
+
+    // check that input points are unchanged
+    for (int i = 0; i < 4; i++) {
+      ensure_equals(savePt[i], pt[i]);
+    }
+  }
+
+
+
 	test_robustlineintersection_data()
 		:
 		pm(),
@@ -231,7 +270,7 @@
 	template<>
 	void object::test<1>()
 	{         
-                computeIntersection(
+                checkIntersection(
                                 "LINESTRING (588750.7429703881 4518950.493668233, 588748.2060409798 4518933.9452804085)",
                                 "LINESTRING (588745.824857241 4518940.742239175, 588748.2060437313 4518933.9452791475)",
                                 1,
@@ -244,7 +283,7 @@
 	template<>
 	void object::test<2>()
 	{         
-                computeIntersection(
+                checkIntersection(
                                 "LINESTRING (588743.626135934 4518924.610969561, 588732.2822865889 4518925.4314047815)",
                                 "LINESTRING (588739.1191384895 4518927.235700594, 588731.7854614238 4518924.578370095)",
                                 1,
@@ -267,7 +306,7 @@
 	   intPt.push_back(Coordinate(2089426.5233462777, 1180182.3877339689));
 	   intPt.push_back(Coordinate(2085646.6891757075, 1195618.7333999649));
 		
-           computeIntersection(
+           checkIntersection(
                                 "LINESTRING ( 2089426.5233462777 1180182.3877339689, 2085646.6891757075 1195618.7333999649 )",
                                 "LINESTRING ( 1889281.8148903656 1997547.0560044837, 2259977.3672235999 483675.17050843034 )",
                                 2,
@@ -284,7 +323,7 @@
 	   std::vector<Coordinate> intPt;
 	   intPt.push_back(Coordinate(4348437.0557510145, 5552597.375203926));
 		
-                computeIntersection(
+                checkIntersection(
                                 "LINESTRING (4348433.262114629 5552595.478385733, 4348440.849387404 5552599.272022122 )",
                                 "LINESTRING (4348433.26211463  5552595.47838573,  4348440.8493874   5552599.27202212  )",
                                 1,
@@ -308,7 +347,7 @@
 	   std::vector<Coordinate> intPt;
 	   intPt.push_back(Coordinate(4348437.0557510145, 5552597.375203926));
 		
-	   computeIntersection( pt, 1, intPt, 0);
+	   checkIntersection( pt, 1, intPt, 0);
 	}
 #endif // fails
 
@@ -322,7 +361,7 @@
 	template<>
 	void object::test<6>()
 	{         
-    computeIntersection(
+    checkIntersection(
         "LINESTRING (305690.0434123494 254176.46578338774, 305601.9999843455 254243.19999846347)",
         "LINESTRING (305689.6153764265 254177.33102743194, 305692.4999844298 254171.4999983967)",
         1,
@@ -343,7 +382,7 @@
 	template<>
 	void object::test<7>()
 	{         
-    computeIntersectionNone(
+    checkIntersectionNone(
         "LINESTRING (-5.9 163.1, 76.1 250.7)",
         "LINESTRING (14.6 185.0, 96.6 272.6)");
 	}
@@ -362,7 +401,7 @@
 	template<>
 	void object::test<8>()
 	{         
-    computeIntersectionNone(
+    checkIntersectionNone(
         "LINESTRING (-42.0 163.2, 21.2 265.2)",
         "LINESTRING (-26.2 188.7, 37.0 290.7)");
 	}
@@ -383,7 +422,7 @@
 	template<>
 	void object::test<9>()
   {
-    computeIntersection(
+    checkIntersection(
         "LINESTRING (163.81867067 -211.31840378, 165.9174252 -214.1665075)",
         "LINESTRING (2.84139601 -57.95412726, 469.59990601 -502.63851732)",
         1,
@@ -396,7 +435,7 @@
 	template<>
 	void object::test<10>()
   {
-    computeIntersection(
+    checkIntersection(
         "LINESTRING (-58.00593335955 -1.43739086465, -513.86101637525 -457.29247388035)",
         "LINESTRING (-215.22279674875 -158.65425425385, -218.1208801283 -160.68343590235)",
         1,
@@ -404,7 +443,27 @@
         0);
   }
 
+  /**
+   * Tests a case where intersection point is rounded,
+   * and it is computed as a nearest endpoint.
+   * Exposed a bug due to aliasing of endpoint.
+   *
+   * MD 8 Mar 2013
+   *
+   */
+  // testRoundedPointsNotAltered()
+  template<>
+	template<>
+	void object::test<11>()
+  {
+    checkInputNotAltered(
+       "LINESTRING (-58.00593335955 -1.43739086465, -513.86101637525 -457.29247388035)",
+       "LINESTRING (-215.22279674875 -158.65425425385, -218.1208801283 -160.68343590235)",
+       100000 );
+  }
 
 
+
+
 } // namespace tut
 



More information about the geos-commits mailing list