[geos-commits] r4160 - in trunk/tests/unit/operation: linemerge overlay

svn_geos at osgeo.org svn_geos at osgeo.org
Wed Mar 2 04:29:21 PST 2016


Author: mloskot
Date: 2016-03-02 04:29:21 -0800 (Wed, 02 Mar 2016)
New Revision: 4160

Modified:
   trunk/tests/unit/operation/linemerge/LineMergerTest.cpp
   trunk/tests/unit/operation/overlay/OverlayOpUnionTest.cpp
Log:
Test merging MultiLineString result of union.

Remove unnecessary FIXED precision model from the triangle test in OverlayOpUnionTest.cpp.
Add comment to link corresponding tests in OverlayOpUnionTest.cpp and LineMergerTest.cpp.

Modified: trunk/tests/unit/operation/linemerge/LineMergerTest.cpp
===================================================================
--- trunk/tests/unit/operation/linemerge/LineMergerTest.cpp	2016-03-01 15:22:48 UTC (rev 4159)
+++ trunk/tests/unit/operation/linemerge/LineMergerTest.cpp	2016-03-02 12:29:21 UTC (rev 4160)
@@ -232,6 +232,47 @@
     doTest(inpWKT, expWKT);
   }
 
+  // Merge segments of a triangle
+  template<> template<>
+  void object::test<7>()
+  {
+      const char* inpWKT[] = {
+        "LINESTRING(0 0, 0 5)",
+        "LINESTRING(0 5, 5 5)",
+        "LINESTRING(5 5, 5 0)",
+        "LINESTRING(5 0, 0 0)",
+        NULL };
+      const char* expWKT[] = {
+        "LINESTRING(0 0, 0 5, 5 5, 5 0, 0 0)",
+          NULL };
 
+      doTest(inpWKT, expWKT);
+  }
+
+  // Merge union of segments of a triangle
+  template<> template<>
+  void object::test<8>()
+  {
+      GeomPtr line1(readWKT("LINESTRING(0 0, 0 5)"));
+      GeomPtr line2(readWKT("LINESTRING(0 5, 5 5)"));
+      GeomPtr line3(readWKT("LINESTRING(5 5, 5 0)"));
+      GeomPtr line4(readWKT("LINESTRING(5 0, 0 0)"));
+      // Union segments incrementally
+      GeomPtr lines12(line1->Union(line2.get()));
+      GeomPtr lines123(lines12->Union(line3.get())); 
+      GeomPtr lines1234(lines123->Union(line4.get()));
+
+      // MultiLineString expected by design, see corresponding test in OverlayOpUnionTest
+      ensure_equals(lines1234->getGeometryTypeId(), geos::geom::GEOS_MULTILINESTRING);
+
+      // Merge MultiLineString into LineString
+      LineMerger lineMerger;
+      lineMerger.add(lines1234.get());
+      mrgGeoms = lineMerger.getMergedLineStrings();
+
+      GeomPtr expected(readWKT("LINESTRING(0 0, 0 5, 5 5, 5 0, 0 0)"));
+      ensure(contains(*mrgGeoms, expected.get(), true));
+  }
+
 } // namespace tut
 

Modified: trunk/tests/unit/operation/overlay/OverlayOpUnionTest.cpp
===================================================================
--- trunk/tests/unit/operation/overlay/OverlayOpUnionTest.cpp	2016-03-01 15:22:48 UTC (rev 4159)
+++ trunk/tests/unit/operation/overlay/OverlayOpUnionTest.cpp	2016-03-02 12:29:21 UTC (rev 4160)
@@ -43,26 +43,24 @@
     template<>
     void object::test<1>()
     {
-        // Arrange
-        geos::geom::PrecisionModel pm(1e+13);
-        GeometryFactoryPtr factory = geos::geom::GeometryFactory::create(&pm);
+        GeometryFactoryPtr factory = geos::geom::GeometryFactory::create();
         geos::io::WKTReader reader(*factory);
         GeometryPtr line1(reader.read("LINESTRING(0 0, 0 5)"));
         GeometryPtr line2(reader.read("LINESTRING(0 5, 5 5)"));
         GeometryPtr line3(reader.read("LINESTRING(5 5, 5 0)"));
         GeometryPtr line4(reader.read("LINESTRING(5 0, 0 0)"));
 
-        // Act: union segments incrementally
+        // union segments incrementally
         GeometryPtr lines12(line1->Union(line2.get()));
         GeometryPtr lines123(lines12->Union(line3.get())); 
         GeometryPtr lines1234(lines123->Union(line4.get()));
 
-        // Assert
         ensure_equals(lines1234->getGeometryTypeId(), geos::geom::GEOS_MULTILINESTRING);
         
         // NOTE: Since the union operation makes no effort to simplify and
         // drop nodes of degree 2 from the built topology,
         // do not expect GEOS_LINESTRING.
+        // See LineMergerTest where the test triangle is generated as a single LineString.
     }
 
 } // namespace tut



More information about the geos-commits mailing list