[geos-commits] r3849 - in trunk: include/geos/geom tests/unit/geom

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Jul 25 13:51:22 PDT 2013


Author: strk
Date: 2013-07-25 13:51:22 -0700 (Thu, 25 Jul 2013)
New Revision: 3849

Modified:
   trunk/include/geos/geom/CoordinateList.h
   trunk/tests/unit/geom/CoordinateListTest.cpp
Log:
closeRing() method added in CoordinateList class

Patch by Vishal Tiwari <hi.vishal123 at gmail.com>

Modified: trunk/include/geos/geom/CoordinateList.h
===================================================================
--- trunk/include/geos/geom/CoordinateList.h	2013-07-23 11:01:38 UTC (rev 3848)
+++ trunk/include/geos/geom/CoordinateList.h	2013-07-25 20:51:22 UTC (rev 3849)
@@ -157,7 +157,16 @@
 		ret->assign(coords.begin(), coords.end());
 		return ret;
 	}
+	void closeRing()
+	{   
+		if(!coords.empty() && ! (*(coords.begin())).equals(*(coords.end())))
+		{   
+			Coordinate c= *(coords.begin());
+			coords.insert(coords.end(),c);
+		}   
+	}   
 
+
 private:
 
 	std::list<Coordinate> coords;

Modified: trunk/tests/unit/geom/CoordinateListTest.cpp
===================================================================
--- trunk/tests/unit/geom/CoordinateListTest.cpp	2013-07-23 11:01:38 UTC (rev 3848)
+++ trunk/tests/unit/geom/CoordinateListTest.cpp	2013-07-25 20:51:22 UTC (rev 3849)
@@ -129,6 +129,42 @@
     clist.insert(it, Coordinate(0, 0), false);
     ensure_equals( clist.size(), 3u );
   }
+  //Test to check the functioning of closeRing() method.
+  template<>
+  template<>
+  void object::test<3>()
+  {
+	  using geos::geom::Coordinate;
 
+	  const Coordinate a(0,0);
+	  const Coordinate b(10,10);
+	  const Coordinate c(45,60);
+	  const Coordinate d(100,0);
 
+	  std::auto_ptr< std::vector<Coordinate> > v( new std::vector<Coordinate>() );
+	  v->push_back(a);                 
+	  v->push_back(b);                         
+	  v->push_back(c);                                 
+	  v->push_back(d);                                         
+	  geos::geom::CoordinateList coordlist(*v);
+
+	  coordlist.closeRing(); 
+
+	  geos::geom::CoordinateList::iterator it1,it2;
+	  it1 = coordlist.begin();
+	  it2 = --coordlist.end();
+	  ensure_equals(*it1,*it2);
+
+	  /* for(CoordinateList::iterator it=coordlist.begin() ; it!=coordlist.end() ; ++it)
+	     {                                                                                       
+	     cout << (*it).x << " " << (*it).y << endl;
+	     }*/                                                                                               
+
+
+	  //If the list is empty::
+	  coordlist.erase(coordlist.begin(),coordlist.end());
+	  coordlist.closeRing();
+	  ensure_equals(coordlist.empty(), true);
+
+  }
 } // namespace tut



More information about the geos-commits mailing list