[geos-commits] [SCM] GEOS branch svn-3.5 updated. 82a83a8f6b6df317d9f5c12f3d9d8a9373d9f95e

git at osgeo.org git at osgeo.org
Mon Jul 30 18:13:16 PDT 2018


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, svn-3.5 has been updated
       via  82a83a8f6b6df317d9f5c12f3d9d8a9373d9f95e (commit)
      from  5c47024ce7bf530221e678bdb5db210296a4151c (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 82a83a8f6b6df317d9f5c12f3d9d8a9373d9f95e
Author: Daniel Baston <dbaston at gmail.com>
Date:   Mon Jul 30 21:04:41 2018 -0400

    Fix infinite loop in GEOSClipByRect
    
    Fixes #865
    Closes https://github.com/libgeos/geos/pull/110

diff --git a/NEWS b/NEWS
index 2ad72b4..4c89440 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+Changes in 3.5.2
+2018-XX-XX
+
+-Bug fixes / improvements
+  - Fix infinite loop in GEOSClipByRect (#865, Dan Baston and Raúl Marín)
+
 Changes in 3.5.1
 2015-10-25
 
diff --git a/src/operation/intersection/RectangleIntersection.cpp b/src/operation/intersection/RectangleIntersection.cpp
index dc0ee4f..25312a8 100644
--- a/src/operation/intersection/RectangleIntersection.cpp
+++ b/src/operation/intersection/RectangleIntersection.cpp
@@ -60,6 +60,11 @@ bool different(double x1, double y1, double x2, double y2)
 inline
 void clip_one_edge(double & x1, double & y1, double x2, double y2, double limit)
 {
+  if (x2 == limit) {
+  	y1 = y2;
+    x1 = x2;
+  }
+
   if(x1 != x2)
 	{
 	  y1 += (y2-y1)*(limit-x1)/(x2-x1);
diff --git a/src/operation/intersection/RectangleIntersectionBuilder.cpp b/src/operation/intersection/RectangleIntersectionBuilder.cpp
index ee886ce..8d7d7b8 100644
--- a/src/operation/intersection/RectangleIntersectionBuilder.cpp
+++ b/src/operation/intersection/RectangleIntersectionBuilder.cpp
@@ -22,6 +22,7 @@
 #include <geos/geom/LineString.h>
 #include <geos/geom/LinearRing.h>
 #include <geos/algorithm/CGAlgorithms.h>
+#include <geos/util/IllegalArgumentException.h>
 
 #include <cmath> // for fabs()
 
@@ -184,6 +185,13 @@ double distance(const Rectangle & rect,
   Rectangle::Position pos = rect.position(x1,y1);
   Rectangle::Position endpos = rect.position(x2,y2);
 
+  if (pos & Rectangle::Position::Outside ||
+      endpos & Rectangle::Position::Outside ||
+	  pos & Rectangle::Position::Inside ||
+	  endpos & Rectangle::Position::Inside) {
+  	throw geos::util::IllegalArgumentException("Can't compute distance to non-boundary position.");
+  }
+
   while(true)
 	{
 	  // Close up when we have the same edge and the
diff --git a/tests/unit/operation/intersection/RectangleIntersectionTest.cpp b/tests/unit/operation/intersection/RectangleIntersectionTest.cpp
index 7ac8ccb..a4c7ee2 100644
--- a/tests/unit/operation/intersection/RectangleIntersectionTest.cpp
+++ b/tests/unit/operation/intersection/RectangleIntersectionTest.cpp
@@ -104,7 +104,6 @@ namespace tut
     typedef group::object object;
 
     group test_rectangleintersectiontest_group("geos::operation::intersection::RectangleIntersection");
-
     // inside
     template<> template<> void object::test<1>()
     {
@@ -1517,4 +1516,19 @@ namespace tut
         "POLYGON((0 0,0 10,10 10,10 0,0 0))";
       doClipTest(inp, exp, r);
     }
+
+    // PostGIS hanging unit test
+    template<> template<> void object::test<208>()
+    {
+      Rectangle r(3.0481343214686657e-14, -20000000.000000, 20000000.000000, -1.000000);
+      const char *clip =
+        "POLYGON((3.0481343214686657e-14 -20000000, 200000000 -20000000, 200000000 -1, 3.0481343214686657e-14 -1, 3.0481343214686657e-14 -20000000))";
+      const char *inp =
+        "POLYGON((3.0481343214686657e-14 -20000000, 3.0481343214686657e-14 -1, 1.570795680861262382313481289e-3 -0.999998766299703523152686557296, 3.141587485909849188081555127e-3 -0.999995065201858102099663483386, 3.0481343214686657e-14 -20000000))";
+
+      GeomPtr isect{readWKT(clip)->intersection(readWKT(inp).get())};
+      std::string exp = wktwriter.write(isect.get());
+
+      doClipTest(inp, exp, r, 1e-20);
+    }
 }

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

Summary of changes:
 NEWS                                                     |  6 ++++++
 src/operation/intersection/RectangleIntersection.cpp     |  5 +++++
 .../intersection/RectangleIntersectionBuilder.cpp        |  8 ++++++++
 .../operation/intersection/RectangleIntersectionTest.cpp | 16 +++++++++++++++-
 4 files changed, 34 insertions(+), 1 deletion(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list