[geos-commits] r3163 - in trunk: src/operation/sharedpaths tests/unit/operation/sharedpaths

svn_geos at osgeo.org svn_geos at osgeo.org
Wed Dec 22 11:28:08 EST 2010


Author: strk
Date: 2010-12-22 08:28:08 -0800 (Wed, 22 Dec 2010)
New Revision: 3163

Modified:
   trunk/src/operation/sharedpaths/SharedPathsOp.cpp
   trunk/tests/unit/operation/sharedpaths/SharedPathsOpTest.cpp
Log:
Fix computation of shared path direction when path starts or ends on the first-last point of a closed line. Fixes ticket #391. Includes automated testing.

Modified: trunk/src/operation/sharedpaths/SharedPathsOp.cpp
===================================================================
--- trunk/src/operation/sharedpaths/SharedPathsOp.cpp	2010-12-22 09:42:40 UTC (rev 3162)
+++ trunk/src/operation/sharedpaths/SharedPathsOp.cpp	2010-12-22 16:28:08 UTC (rev 3163)
@@ -147,8 +147,21 @@
 
   const Coordinate& pt1 = edge.getCoordinateN(0);
   const Coordinate& pt2 = edge.getCoordinateN(1);
-  LinearLocation l1 = LocationIndexOfPoint::indexOf(&geom, pt1);
-  LinearLocation l2 = LocationIndexOfPoint::indexOf(&geom, pt2);
+
+  /*
+   * We move the coordinate somewhat closer, to avoid
+   * vertices of the geometry being checked (geom). 
+   *
+   * This is mostly only needed when one of the two points
+   * of the edge is an endpoint of a _closed_ geom.
+   * We have an unit test for this...
+   */
+  Coordinate pt1i = LinearLocation::pointAlongSegmentByFraction(pt1, pt2, 0.1);
+  Coordinate pt2i = LinearLocation::pointAlongSegmentByFraction(pt1, pt2, 0.9);
+
+  LinearLocation l1 = LocationIndexOfPoint::indexOf(&geom, pt1i);
+  LinearLocation l2 = LocationIndexOfPoint::indexOf(&geom, pt2i);
+
   return l1.compareTo(l2) < 0;
 }
 

Modified: trunk/tests/unit/operation/sharedpaths/SharedPathsOpTest.cpp
===================================================================
--- trunk/tests/unit/operation/sharedpaths/SharedPathsOpTest.cpp	2010-12-22 09:42:40 UTC (rev 3162)
+++ trunk/tests/unit/operation/sharedpaths/SharedPathsOpTest.cpp	2010-12-22 16:28:08 UTC (rev 3163)
@@ -322,5 +322,69 @@
     ensure(forwDir.empty());
   }
 
+  // line - line_closed_no_rhr
+  template<> template<>
+  void object::test<18>()
+  {
+    GeomPtr g0(wktreader.read("LINESTRING( 0  0, 10 0)"));
+    GeomPtr g1(wktreader.read("LINESTRING( 0  0, 10 0, 10 10, 0 10, 0 0 )"));
+
+    forwDir.clear(); backDir.clear();
+    SharedPathsOp::sharedPathsOp(*g0, *g1, forwDir, backDir);
+    ensure_equals(forwDir.size(), 1u);
+    ensure_equals(wktwriter.write(forwDir[0]), "LINESTRING (0 0, 10 0)"); 
+    SharedPathsOp::clearEdges(forwDir);
+
+    ensure(backDir.empty());
+  }
+
+  // line_closed_no_rhr - line
+  template<> template<>
+  void object::test<19>()
+  {
+    GeomPtr g0(wktreader.read("LINESTRING( 0  0, 10 0, 10 10, 0 10, 0 0 )"));
+    GeomPtr g1(wktreader.read("LINESTRING( 0  0, 10 0)"));
+
+    forwDir.clear(); backDir.clear();
+    SharedPathsOp::sharedPathsOp(*g0, *g1, forwDir, backDir);
+    ensure_equals(forwDir.size(), 1u);
+    ensure_equals(wktwriter.write(forwDir[0]), "LINESTRING (0 0, 10 0)"); 
+    SharedPathsOp::clearEdges(forwDir);
+
+    ensure(backDir.empty());
+  }
+
+  // line - line_closed_rhr (see ticket #391)
+  template<> template<>
+  void object::test<20>()
+  {
+    GeomPtr g0(wktreader.read("LINESTRING( 0  0, 10 0)"));
+    GeomPtr g1(wktreader.read("LINESTRING( 0  0, 0 10, 10 10, 10 0, 0 0 )"));
+
+    forwDir.clear(); backDir.clear();
+    SharedPathsOp::sharedPathsOp(*g0, *g1, forwDir, backDir);
+    ensure_equals(backDir.size(), 1u);
+    ensure_equals(wktwriter.write(backDir[0]), "LINESTRING (0 0, 10 0)"); 
+    SharedPathsOp::clearEdges(backDir);
+
+    ensure(forwDir.empty());
+  }
+
+  // line_closed_rhr - line 
+  template<> template<>
+  void object::test<21>()
+  {
+    GeomPtr g0(wktreader.read("LINESTRING( 0  0, 0 10, 10 10, 10 0, 0 0 )"));
+    GeomPtr g1(wktreader.read("LINESTRING( 0  0, 10 0)"));
+
+    forwDir.clear(); backDir.clear();
+    SharedPathsOp::sharedPathsOp(*g0, *g1, forwDir, backDir);
+    ensure_equals(backDir.size(), 1u);
+    ensure_equals(wktwriter.write(backDir[0]), "LINESTRING (10 0, 0 0)"); 
+    SharedPathsOp::clearEdges(backDir);
+
+    ensure(forwDir.empty());
+  }
+
 } // namespace tut
 



More information about the geos-commits mailing list