[geos-commits] r3999 - in branches/3.3: . src/geom tests/unit tests/unit/geom tests/unit/geom/Geometry

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Sep 9 07:35:52 PDT 2014


Author: strk
Date: 2014-09-09 07:35:51 -0700 (Tue, 09 Sep 2014)
New Revision: 3999

Added:
   branches/3.3/tests/unit/geom/Geometry/equalsTest.cpp
Modified:
   branches/3.3/NEWS
   branches/3.3/src/geom/Envelope.cpp
   branches/3.3/src/geom/Geometry.cpp
   branches/3.3/tests/unit/Makefile.am
   branches/3.3/tests/unit/geom/EnvelopeTest.cpp
   branches/3.3/tests/unit/geom/PointTest.cpp
Log:
Fix Empty to Empty equals response (#703)

Modified: branches/3.3/NEWS
===================================================================
--- branches/3.3/NEWS	2014-08-25 07:44:09 UTC (rev 3998)
+++ branches/3.3/NEWS	2014-09-09 14:35:51 UTC (rev 3999)
@@ -3,6 +3,7 @@
 
 - Bug fixes / improvements
     - Throw a ParseException on missing chars from HEXWKB string (#675)
+    - Fix Empty to Empty equals (#703)
 
 Changes in 3.3.9
 2013-09-04

Modified: branches/3.3/src/geom/Envelope.cpp
===================================================================
--- branches/3.3/src/geom/Envelope.cpp	2014-08-25 07:44:09 UTC (rev 3998)
+++ branches/3.3/src/geom/Envelope.cpp	2014-09-09 14:35:51 UTC (rev 3999)
@@ -326,7 +326,7 @@
 bool
 Envelope::equals(const Envelope* other) const
 {
-	if (isNull() || other->isNull()) { return false; }
+	if (isNull()) return other->isNull();
 	return  other->getMinX() == minx &&
 			other->getMaxX() == maxx &&
 			other->getMinY() == miny &&

Modified: branches/3.3/src/geom/Geometry.cpp
===================================================================
--- branches/3.3/src/geom/Geometry.cpp	2014-08-25 07:44:09 UTC (rev 3998)
+++ branches/3.3/src/geom/Geometry.cpp	2014-09-09 14:35:51 UTC (rev 3999)
@@ -454,6 +454,10 @@
 	if (! getEnvelopeInternal()->equals(g->getEnvelopeInternal()))
 		return false;
 #endif
+
+	if (isEmpty()) return g->isEmpty();
+	else if (g->isEmpty()) return isEmpty();
+
 	auto_ptr<IntersectionMatrix> im ( relate(g) );
 	bool res=im->isEquals(getDimension(), g->getDimension());
 	return res;

Modified: branches/3.3/tests/unit/Makefile.am
===================================================================
--- branches/3.3/tests/unit/Makefile.am	2014-08-25 07:44:09 UTC (rev 3998)
+++ branches/3.3/tests/unit/Makefile.am	2014-09-09 14:35:51 UTC (rev 3999)
@@ -50,6 +50,7 @@
 	geom/EnvelopeTest.cpp \
 	geom/Geometry/clone.cpp \
 	geom/Geometry/coversTest.cpp \
+	geom/Geometry/equalsTest.cpp \
 	geom/Geometry/isRectangleTest.cpp \
 	geom/GeometryFactoryTest.cpp \
 	geom/IntersectionMatrixTest.cpp \

Modified: branches/3.3/tests/unit/geom/EnvelopeTest.cpp
===================================================================
--- branches/3.3/tests/unit/geom/EnvelopeTest.cpp	2014-08-25 07:44:09 UTC (rev 3998)
+++ branches/3.3/tests/unit/geom/EnvelopeTest.cpp	2014-09-09 14:35:51 UTC (rev 3999)
@@ -103,6 +103,9 @@
         ensure( !zero2.isNull() );
         ensure( !box.isNull() );
 
+        /* See http://trac.osgeo.org/geos/ticket/703 */
+        ensure( empty.equals( &empty ) );
+
         ensure( !empty.equals( &zero ) );
         ensure( !zero.equals( &empty ) );
 

Added: branches/3.3/tests/unit/geom/Geometry/equalsTest.cpp
===================================================================
--- branches/3.3/tests/unit/geom/Geometry/equalsTest.cpp	                        (rev 0)
+++ branches/3.3/tests/unit/geom/Geometry/equalsTest.cpp	2014-09-09 14:35:51 UTC (rev 3999)
@@ -0,0 +1,68 @@
+// 
+// Test Suite for Geometry's equals() function
+
+// tut
+#include <tut.hpp>
+// geos
+#include <geos/geom/GeometryFactory.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/Polygon.h>
+#include <geos/io/WKTReader.h>
+// std
+#include <memory>
+#include <string>
+
+namespace tut {
+
+//
+// Test Group
+//
+
+struct test_equals_data
+{
+	typedef std::auto_ptr<geos::geom::Geometry> GeomAutoPtr;
+	geos::geom::GeometryFactory factory;
+	geos::io::WKTReader reader;
+
+	test_equals_data()
+	    : reader(&factory)
+	{}
+};
+
+typedef test_group<test_equals_data> group;
+typedef group::object object;
+
+group test_equals_data("geos::geom::Geometry::equals");
+
+//
+// Test Cases
+//
+
+// Empty equals empty
+// See http://trac.osgeo.org/geos/ticket/703
+
+template<> template<> void object::test<1>() {
+
+	GeomAutoPtr g1(reader.read("POINT EMPTY"));
+	ensure( g1->equals(g1.get()) );
+
+	GeomAutoPtr g2(reader.read("LINESTRING EMPTY"));
+	ensure( g2->equals(g2.get()) );
+	ensure( g2->equals(g1.get()) );
+
+	GeomAutoPtr g3(reader.read("POLYGON EMPTY"));
+	ensure( g3->equals(g3.get()) );
+	ensure( g3->equals(g2.get()) );
+	ensure( g3->equals(g1.get()) );
+
+	GeomAutoPtr g4(reader.read("GEOMETRYCOLLECTION EMPTY"));
+	ensure( g4->equals(g4.get()) );
+	ensure( g4->equals(g3.get()) );
+	ensure( g4->equals(g2.get()) );
+	ensure( g4->equals(g1.get()) );
+
+}
+
+
+} // namespace tut
+

Modified: branches/3.3/tests/unit/geom/PointTest.cpp
===================================================================
--- branches/3.3/tests/unit/geom/PointTest.cpp	2014-08-25 07:44:09 UTC (rev 3998)
+++ branches/3.3/tests/unit/geom/PointTest.cpp	2014-09-09 14:35:51 UTC (rev 3999)
@@ -372,7 +372,7 @@
 	{
 		GeometryAutoPtr geo(empty_point_->clone());
 
-		ensure( !empty_point_->equals(geo.get()) );
+		ensure( empty_point_->equals(geo.get()) );
 	}
 
 	// Test of equals() for non-empty Point (1.234,5.678)



More information about the geos-commits mailing list