[geos-commits] [SCM] GEOS branch master updated. 9924c15fc0611e2e49d5665b18122bfa4c5fe1c0

git at osgeo.org git at osgeo.org
Fri Sep 27 11:49:00 PDT 2019


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, master has been updated
       via  9924c15fc0611e2e49d5665b18122bfa4c5fe1c0 (commit)
      from  f7c913f363de8f12557e749eec2db7ab01312d83 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 9924c15fc0611e2e49d5665b18122bfa4c5fe1c0
Author: Daniel Baston <dbaston at gmail.com>
Date:   Fri Sep 27 14:46:36 2019 -0400

    Ignore z in Coordinate::HashCode
    
    Including z was inconsistent with the behavior of the equality operator,
    and caused equivalent coordinates to be hashed into different bins.
    
    Identified by Raul MarĂ­n, debugged by Paul Ramsey.

diff --git a/include/geos/geom/Coordinate.inl b/include/geos/geom/Coordinate.inl
index 7accf73..983931e 100644
--- a/include/geos/geom/Coordinate.inl
+++ b/include/geos/geom/Coordinate.inl
@@ -143,7 +143,7 @@ INLINE size_t
 Coordinate::HashCode::operator()(const geos::geom::Coordinate &c) const {
     size_t h = std::hash<double>{}(c.x);
     h ^= std::hash<double>{}(c.y) << 1;
-    h ^= std::hash<double>{}(c.z) << 1;
+    // z ordinate ignored for consistency with operator==
     return h;
 }
 
diff --git a/tests/unit/geom/CoordinateTest.cpp b/tests/unit/geom/CoordinateTest.cpp
index 1b28c3b..e0d64e2 100644
--- a/tests/unit/geom/CoordinateTest.cpp
+++ b/tests/unit/geom/CoordinateTest.cpp
@@ -6,6 +6,7 @@
 #include <geos/geom/Coordinate.h>
 // std
 #include <cmath>
+#include <unordered_set>
 
 namespace tut {
 //
@@ -196,5 +197,26 @@ void object::test<9>
     ensure(0 != std::isnan(null_coord.z));
 }
 
+template<>
+template<>
+void object::test<10>
+()
+{
+    using geos::geom::Coordinate;
+
+    std::unordered_set<Coordinate, Coordinate::HashCode> coords;
+
+    coords.emplace(1, 2);
+    ensure_equals(coords.size(), 1ul);
+
+    coords.emplace(2, 1);
+    ensure_equals(coords.size(), 2ul);
+
+    // hash function defined consistently with equality operator
+    // and considers X and Y only
+    coords.emplace(1, 2, 3);
+    ensure_equals(coords.size(), 2ul);
+}
+
 } // namespace tut
 
diff --git a/tests/xmltester/tests/issue/issue-geos-990.xml b/tests/xmltester/tests/issue/issue-geos-990.xml
new file mode 100644
index 0000000..ae70347
--- /dev/null
+++ b/tests/xmltester/tests/issue/issue-geos-990.xml
@@ -0,0 +1,19 @@
+<run>
+<precisionModel type="FLOATING" />
+<case>
+<desc>
+Difference of two 3D geometries
+</desc>
+<a>
+LINESTRING(0 0,0 10,10 10,10 0,0 0)
+</a>
+<b>
+GEOMETRYCOLLECTION Z (GEOMETRYCOLLECTION Z (MULTILINESTRING Z ((0 0 10,10 0 20),(10 0 20,10 10 30)),LINESTRING Z (0 10 20,10 10 30)),LINESTRING Z (0 0 10,0 10 20))'::geometry
+</b>
+<test>
+<op name="difference" arg1="A" arg2="B">
+LINESTRING EMPTY
+</op>
+</test>
+</case>
+</run>

-----------------------------------------------------------------------

Summary of changes:
 include/geos/geom/Coordinate.inl               |  2 +-
 tests/unit/geom/CoordinateTest.cpp             | 22 ++++++++++++++++++++++
 tests/xmltester/tests/issue/issue-geos-990.xml | 19 +++++++++++++++++++
 3 files changed, 42 insertions(+), 1 deletion(-)
 create mode 100644 tests/xmltester/tests/issue/issue-geos-990.xml


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list