[geos-commits] r4001 - in trunk: 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:46:09 PDT 2014
Author: strk
Date: 2014-09-09 07:46:08 -0700 (Tue, 09 Sep 2014)
New Revision: 4001
Added:
trunk/tests/unit/geom/Geometry/equalsTest.cpp
Modified:
trunk/src/geom/Envelope.cpp
trunk/src/geom/Geometry.cpp
trunk/tests/unit/Makefile.am
trunk/tests/unit/geom/EnvelopeTest.cpp
trunk/tests/unit/geom/PointTest.cpp
Log:
Fix Empty to Empty equals response (#703)
Modified: trunk/src/geom/Envelope.cpp
===================================================================
--- trunk/src/geom/Envelope.cpp 2014-09-09 14:36:35 UTC (rev 4000)
+++ trunk/src/geom/Envelope.cpp 2014-09-09 14:46:08 UTC (rev 4001)
@@ -325,7 +325,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: trunk/src/geom/Geometry.cpp
===================================================================
--- trunk/src/geom/Geometry.cpp 2014-09-09 14:36:35 UTC (rev 4000)
+++ trunk/src/geom/Geometry.cpp 2014-09-09 14:46:08 UTC (rev 4001)
@@ -435,6 +435,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: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am 2014-09-09 14:36:35 UTC (rev 4000)
+++ trunk/tests/unit/Makefile.am 2014-09-09 14:46:08 UTC (rev 4001)
@@ -49,6 +49,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: trunk/tests/unit/geom/EnvelopeTest.cpp
===================================================================
--- trunk/tests/unit/geom/EnvelopeTest.cpp 2014-09-09 14:36:35 UTC (rev 4000)
+++ trunk/tests/unit/geom/EnvelopeTest.cpp 2014-09-09 14:46:08 UTC (rev 4001)
@@ -102,6 +102,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: trunk/tests/unit/geom/Geometry/equalsTest.cpp
===================================================================
--- trunk/tests/unit/geom/Geometry/equalsTest.cpp (rev 0)
+++ trunk/tests/unit/geom/Geometry/equalsTest.cpp 2014-09-09 14:46:08 UTC (rev 4001)
@@ -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: trunk/tests/unit/geom/PointTest.cpp
===================================================================
--- trunk/tests/unit/geom/PointTest.cpp 2014-09-09 14:36:35 UTC (rev 4000)
+++ trunk/tests/unit/geom/PointTest.cpp 2014-09-09 14:46:08 UTC (rev 4001)
@@ -371,7 +371,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