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

svn_geos at osgeo.org svn_geos at osgeo.org
Mon Nov 29 04:34:41 EST 2010


Author: strk
Date: 2010-11-29 01:34:41 -0800 (Mon, 29 Nov 2010)
New Revision: 3132

Modified:
   trunk/include/geos/operation/sharedpaths/SharedPathsOp.h
   trunk/src/operation/sharedpaths/SharedPathsOp.cpp
   trunk/tests/unit/operation/sharedpaths/SharedPathsOpTest.cpp
Log:
Have SharedPathsOp throw an exception on illegal (non-lineal) arg

Modified: trunk/include/geos/operation/sharedpaths/SharedPathsOp.h
===================================================================
--- trunk/include/geos/operation/sharedpaths/SharedPathsOp.h	2010-11-29 09:34:26 UTC (rev 3131)
+++ trunk/include/geos/operation/sharedpaths/SharedPathsOp.h	2010-11-29 09:34:41 UTC (rev 3132)
@@ -122,12 +122,15 @@
   bool isForward(const geom::LineString& edge,
                  const geom::Geometry& geom);
 
-  // Check if the given edge goes in the same direction over
-  // the two geometries.
+  /// Check if the given edge goes in the same direction over
+  /// the two geometries.
   bool isSameDirection(const geom::LineString& edge) {
     return (isForward(edge, _g1) == isForward(edge, _g2));
   }
 
+  /// Throw an IllegalArgumentException if the geom is not linear
+  void checkLinealInput(const geom::Geometry& g);
+
   const geom::Geometry& _g1;
   const geom::Geometry& _g2;
   const geom::GeometryFactory& _gf;

Modified: trunk/src/operation/sharedpaths/SharedPathsOp.cpp
===================================================================
--- trunk/src/operation/sharedpaths/SharedPathsOp.cpp	2010-11-29 09:34:26 UTC (rev 3131)
+++ trunk/src/operation/sharedpaths/SharedPathsOp.cpp	2010-11-29 09:34:41 UTC (rev 3132)
@@ -20,11 +20,12 @@
 #include <geos/operation/sharedpaths/SharedPathsOp.h>
 #include <geos/geom/Geometry.h>
 #include <geos/geom/LineString.h>
+#include <geos/geom/MultiLineString.h>
 #include <geos/linearref/LinearLocation.h>
 #include <geos/linearref/LocationIndexOfPoint.h>
 #include <geos/operation/overlay/OverlayOp.h>
 #include <geos/util/IllegalArgumentException.h>
-#include <geos/geom/util/LinearComponentExtracter.h>
+//#include <geos/geom/util/LinearComponentExtracter.h>
 
 using namespace geos::geom;
 
@@ -50,8 +51,21 @@
   _g2(g2),
   _gf(*g1.getFactory())
 {
+  checkLinealInput(_g1);
+  checkLinealInput(_g2);
 }
 
+/* private */
+void
+SharedPathsOp::checkLinealInput(const geom::Geometry& g)
+{
+  if ( ! dynamic_cast<const LineString*>(&g) &&
+       ! dynamic_cast<const MultiLineString*>(&g) )
+  {
+    throw util::IllegalArgumentException("Geometry is not lineal");
+  }
+}
+
 /* public */
 void
 SharedPathsOp::getSharedPaths(PathList& forwDir, PathList& backDir)

Modified: trunk/tests/unit/operation/sharedpaths/SharedPathsOpTest.cpp
===================================================================
--- trunk/tests/unit/operation/sharedpaths/SharedPathsOpTest.cpp	2010-11-29 09:34:26 UTC (rev 3131)
+++ trunk/tests/unit/operation/sharedpaths/SharedPathsOpTest.cpp	2010-11-29 09:34:41 UTC (rev 3132)
@@ -11,6 +11,7 @@
 #include <geos/geom/LineString.h>
 #include <geos/io/WKTReader.h>
 #include <geos/io/WKTWriter.h>
+#include <geos/util/IllegalArgumentException.h>
 // std
 #include <memory>
 #include <string>
@@ -57,28 +58,34 @@
   // Test Cases
   //
 
-  // Point-Point (disjoint)
+  // Point (illegal arg)
   template<> template<>
   void object::test<1>()
   {
     GeomPtr g0(wktreader.read("POINT(0 0)"));
     GeomPtr g1(wktreader.read("POINT(1 1)"));
-    forwDir.clear(); backDir.clear();
-    SharedPathsOp::sharedPathsOp(*g0, *g1, forwDir, backDir);
-    ensure(forwDir.empty());
-    ensure(backDir.empty());
+    bool threw = false;
+    try {
+      SharedPathsOp::sharedPathsOp(*g0, *g1, forwDir, backDir);
+    } catch (const geos::util::IllegalArgumentException& ex) {
+      threw = true;
+    }
+    ensure(threw);
   }
 
-  // Point-Point (same)
+  // Poly (illegal arg)
   template<> template<>
   void object::test<2>()
   {
-    GeomPtr g0(wktreader.read("POINT(0 0)"));
-    GeomPtr g1(wktreader.read("POINT(0 0)"));
-    forwDir.clear(); backDir.clear();
-    SharedPathsOp::sharedPathsOp(*g0, *g1, forwDir, backDir);
-    ensure(forwDir.empty());
-    ensure(backDir.empty());
+    GeomPtr g0(wktreader.read("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))"));
+    GeomPtr g1(wktreader.read("LINESTRING(0 0, 10 0)"));
+    bool threw = false;
+    try {
+      SharedPathsOp::sharedPathsOp(*g0, *g1, forwDir, backDir);
+    } catch (const geos::util::IllegalArgumentException& ex) {
+      threw = true;
+    }
+    ensure(threw);
   }
 
   // Line-Line (disjoint)



More information about the geos-commits mailing list