[geos-commits] [SCM] GEOS branch master updated. de4927dfa262c31f439191ea2bb6aae9f707b689

git at osgeo.org git at osgeo.org
Mon Jul 30 18:05:24 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, master has been updated
       via  de4927dfa262c31f439191ea2bb6aae9f707b689 (commit)
      from  3de3ccc96a22030e65d0200f4d35a076617361d9 (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 de4927dfa262c31f439191ea2bb6aae9f707b689
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/src/operation/intersection/RectangleIntersection.cpp b/src/operation/intersection/RectangleIntersection.cpp
index 850fb0b..04f5615 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 ec61493..5bd0c4e 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 0bd73eb..89c60ed 100644
--- a/tests/unit/operation/intersection/RectangleIntersectionTest.cpp
+++ b/tests/unit/operation/intersection/RectangleIntersectionTest.cpp
@@ -101,7 +101,6 @@ namespace tut
     typedef group::object object;
 
     group test_rectangleintersectiontest_group("geos::operation::intersection::RectangleIntersection");
-
     // inside
     template<> template<> void object::test<1>()
     {
@@ -1514,4 +1513,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:
 src/operation/intersection/RectangleIntersection.cpp     |  5 +++++
 .../intersection/RectangleIntersectionBuilder.cpp        |  8 ++++++++
 .../operation/intersection/RectangleIntersectionTest.cpp | 16 +++++++++++++++-
 3 files changed, 28 insertions(+), 1 deletion(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list