[geos-commits] r2497 - trunk/tests/unit/operation/distance

svn_geos at osgeo.org svn_geos at osgeo.org
Fri May 8 08:27:23 EDT 2009


Author: strk
Date: 2009-05-08 08:27:23 -0400 (Fri, 08 May 2009)
New Revision: 2497

Modified:
   trunk/tests/unit/operation/distance/DistanceOpTest.cpp
Log:
Add the complete set of tests for closedPoints


Modified: trunk/tests/unit/operation/distance/DistanceOpTest.cpp
===================================================================
--- trunk/tests/unit/operation/distance/DistanceOpTest.cpp	2009-05-08 12:11:52 UTC (rev 2496)
+++ trunk/tests/unit/operation/distance/DistanceOpTest.cpp	2009-05-08 12:27:23 UTC (rev 2497)
@@ -31,6 +31,7 @@
 		geos::io::WKTReader wktreader;
 
 		typedef geos::geom::Geometry::AutoPtr GeomPtr;
+		typedef std::auto_ptr<geos::geom::CoordinateSequence> CSPtr;
 
 		test_distanceop_data()
             : gf(), wktreader(&gf)
@@ -50,6 +51,7 @@
 	void object::test<1>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("POINT(0 0)");
 		std::string wkt1("POINT(10 0)");
@@ -60,11 +62,9 @@
 
 		ensure_equals(dist.distance(), 10);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
-        	geos::geom::CoordinateSequence* coords = dist.closestPoints();
-        	ensure(0 != coords);
-		delete coords;
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(0, 0));
+        	ensure_equals(cs->getAt(1), Coordinate(10, 0));
 	}
 
 	template<>
@@ -72,6 +72,7 @@
 	void object::test<2>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("POINT(0 0)");
 		std::string wkt1("MULTIPOINT(10 0, 50 30)");
@@ -82,8 +83,9 @@
 
 		ensure_equals(dist.distance(), 10);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(0, 0));
+        	ensure_equals(cs->getAt(1), Coordinate(10, 0));
 
 	}
 
@@ -92,6 +94,7 @@
 	void object::test<3>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("POINT(3 0)");
 		std::string wkt1("LINESTRING(0 10, 50 10, 100 50)");
@@ -102,8 +105,9 @@
 
 		ensure_equals(dist.distance(), 10);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(3, 0));
+        	ensure_equals(cs->getAt(1), Coordinate(3, 10));
 
 	}
 
@@ -112,6 +116,7 @@
 	void object::test<4>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("POINT(3 0)");
 		std::string wkt1("MULTILINESTRING((34 54, 60 34),(0 10, 50 10, 100 50))");
@@ -122,8 +127,9 @@
 
 		ensure_equals(dist.distance(), 10);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(3, 0));
+        	ensure_equals(cs->getAt(1), Coordinate(3, 10));
 
 	}
 
@@ -132,6 +138,7 @@
 	void object::test<5>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("POINT(35 60)");
 		std::string wkt1("POLYGON((34 54, 60 34, 60 54, 34 54),(50 50, 52 50, 52 48, 50 48, 50 50))");
@@ -142,8 +149,9 @@
 
 		ensure_equals(dist.distance(), 6);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(35, 60));
+        	ensure_equals(cs->getAt(1), Coordinate(35, 54));
 
 	}
 
@@ -152,6 +160,7 @@
 	void object::test<6>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("POINT(35 60)");
 		std::string wkt1("MULTIPOLYGON(((34 54, 60 34, 60 54, 34 54),(50 50, 52 50, 52 48, 50 48, 50 50)),( (100 100, 150 100, 150 150, 100 150, 100 100),(120 120, 120 130, 130 130, 130 120, 120 120)) ))");
@@ -162,8 +171,9 @@
 
 		ensure_equals(dist.distance(), 6);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(35, 60));
+        	ensure_equals(cs->getAt(1), Coordinate(35, 54));
 
 	}
 
@@ -172,6 +182,7 @@
 	void object::test<7>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("POINT(35 60)");
 
@@ -185,9 +196,9 @@
 
 		ensure_equals(dist.distance(), 6);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
-
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(35, 60));
+        	ensure_equals(cs->getAt(1), Coordinate(35, 54));
 	}
 
 	template<>
@@ -195,6 +206,7 @@
 	void object::test<8>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("POINT(35 60)");
 
@@ -208,9 +220,7 @@
 
 		ensure_equals(dist.distance(), DoubleInfinity);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
-
+		ensure_equals(dist.closestPoints(), (void*)0);
 	}
 
 	template<>
@@ -218,6 +228,7 @@
 	void object::test<9>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("MULTIPOINT(10 0, 50 30)");
 		std::string wkt1("POINT(10 0)");
@@ -228,8 +239,9 @@
 
 		ensure_equals(dist.distance(), 0);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(10, 0));
+        	ensure_equals(cs->getAt(1), Coordinate(10, 0));
 
 	}
 
@@ -238,6 +250,7 @@
 	void object::test<10>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("MULTIPOINT(10 0, 50 30)");
 		std::string wkt1("MULTIPOINT(0 0, 150 30)");
@@ -248,8 +261,9 @@
 
 		ensure_equals(dist.distance(), 10);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(10, 0));
+        	ensure_equals(cs->getAt(1), Coordinate(0, 0));
 
 	}
 
@@ -258,6 +272,7 @@
 	void object::test<11>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("MULTIPOINT(3 0, 200 30)");
 		std::string wkt1("LINESTRING(0 10, 50 10, 100 50)");
@@ -268,8 +283,9 @@
 
 		ensure_equals(dist.distance(), 10);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(3, 0));
+        	ensure_equals(cs->getAt(1), Coordinate(3, 10));
 
 	}
 
@@ -278,6 +294,7 @@
 	void object::test<12>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("MULTIPOINT(3 0, -50 30)");
 		std::string wkt1("MULTILINESTRING((34 54, 60 34),(0 10, 50 10, 100 50))");
@@ -288,8 +305,9 @@
 
 		ensure_equals(dist.distance(), 10);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(3, 0));
+        	ensure_equals(cs->getAt(1), Coordinate(3, 10));
 
 	}
 
@@ -298,6 +316,7 @@
 	void object::test<13>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("MULTIPOINT(-100 0, 35 60)");
 		std::string wkt1("POLYGON((34 54, 60 34, 60 54, 34 54),(50 50, 52 50, 52 48, 50 48, 50 50))");
@@ -308,8 +327,9 @@
 
 		ensure_equals(dist.distance(), 6);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(35, 60));
+        	ensure_equals(cs->getAt(1), Coordinate(35, 54));
 
 	}
 
@@ -318,6 +338,7 @@
 	void object::test<14>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("MULTIPOINT(-100 0, 35 60)");
 		std::string wkt1("MULTIPOLYGON(((34 54, 60 34, 60 54, 34 54),(50 50, 52 50, 52 48, 50 48, 50 50)),( (100 100, 150 100, 150 150, 100 150, 100 100),(120 120, 120 130, 130 130, 130 120, 120 120)) ))");
@@ -328,9 +349,9 @@
 
 		ensure_equals(dist.distance(), 6);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
-
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(35, 60));
+        	ensure_equals(cs->getAt(1), Coordinate(35, 54));
 	}
 
 	template<>
@@ -338,6 +359,7 @@
 	void object::test<15>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("MULTIPOINT(-100 0, 35 60)");
 
@@ -351,8 +373,9 @@
 
 		ensure_equals(dist.distance(), 6);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
+        	CSPtr cs ( dist.closestPoints());
+        	ensure_equals(cs->getAt(0), Coordinate(35, 60));
+        	ensure_equals(cs->getAt(1), Coordinate(35, 54));
 
 	}
 
@@ -361,6 +384,7 @@
 	void object::test<16>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("MULTIPOINT(-100 0, 35 60)");
 
@@ -374,8 +398,7 @@
 
 		ensure_equals(dist.distance(), DoubleInfinity);
 
-		// TODO: test closestPoints() and
-		//       closestLocations()
+        	ensure_equals(dist.closestPoints(), (void*)0);
 
 	}
 
@@ -386,6 +409,7 @@
 	void object::test<17>()
 	{
 		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
 
 		std::string wkt0("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))");
 		std::string wkt1("POLYGON((1.25 0.25, 1.25 0.75, 1.75 0.75, 1.75 0.25, 1.25 0.25))");
@@ -396,11 +420,41 @@
 		DistanceOp dist(g0.get(), g1.get());
 		ensure_equals(dist.distance(), 0.25);
 
-        // FIXME: This operation crashes becasue of both GeometryLocation's are NULL
-        //        in DistanceOp::closestPoints()
-        //geos::geom::CoordinateSequence* cs dist.closestPoints();
+        	CSPtr cs ( dist.closestPoints());
+		ensure_equals(cs->getAt(0), Coordinate(1, 0.25));
+		ensure_equals(cs->getAt(1), Coordinate(1.25, 0.25));
 	}
 
+	// Test for isWithinDistance
+	template<>
+	template<>
+	void object::test<18>()
+	{
+		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
+
+		std::string wkt0("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))");
+		std::string wkt1("POLYGON((1.25 0.25, 1.25 0.75, 1.75 0.75, 1.75 0.25, 1.25 0.25))");
+
+		GeomPtr g0(wktreader.read(wkt0));
+		GeomPtr g1(wktreader.read(wkt1));
+
+		ensure_equals(DistanceOp::distance(*g0, *g1), 0.25);
+		ensure(DistanceOp::isWithinDistance(*g0, *g1, 0.26));
+		ensure(!DistanceOp::isWithinDistance(*g0, *g1, 0.24));
+
+		wkt0 = "LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)";
+		wkt1 = "LINESTRING(2 0, 10 1, 10 10)";
+		g0.reset(wktreader.read(wkt0));
+		g1.reset(wktreader.read(wkt1));
+
+		ensure_equals(DistanceOp::distance(*g0, *g1), 1);
+		ensure(DistanceOp::isWithinDistance(*g0, *g1, 2));
+		ensure(!DistanceOp::isWithinDistance(*g0, *g1, 0.8));
+
+		// TODO: test closestPoints
+	}
+
 	// TODO: finish the tests by adding:
 	// 	LINESTRING - *all*
 	// 	MULTILINESTRING - *all*



More information about the geos-commits mailing list