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

git at osgeo.org git at osgeo.org
Tue Aug 27 07:42:23 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  f90b1db9336c440354344c4bca0ae7bab7662800 (commit)
       via  81451a44c31eb5045b6026942051312130886bfe (commit)
      from  395ebff81baf36176fbd529b32cacd4c76927d53 (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 f90b1db9336c440354344c4bca0ae7bab7662800
Merge: 395ebff 81451a4
Author: Daniel Baston <dbaston at gmail.com>
Date:   Tue Aug 27 10:40:40 2019 -0400

    Merge remote-tracking branch 'origin/trac-584'


commit 81451a44c31eb5045b6026942051312130886bfe
Author: Daniel Baston <dbaston at gmail.com>
Date:   Sat Aug 24 21:31:47 2019 -0400

    Add envelope test to Distance::segmentToSegment
    
    JTS commit r652
    Fixes Trac #584

diff --git a/src/algorithm/Distance.cpp b/src/algorithm/Distance.cpp
index f55a3df..8a88a82 100644
--- a/src/algorithm/Distance.cpp
+++ b/src/algorithm/Distance.cpp
@@ -21,6 +21,7 @@
 #include <algorithm>
 
 #include <geos/algorithm/Distance.h>
+#include <geos/geom/Envelope.h>
 #include <geos/util/IllegalArgumentException.h>
 
 namespace geos {
@@ -142,21 +143,29 @@ Distance::segmentToSegment(const geom::Coordinate& A,
         If the numerator in eqn 1 is also zero, AB & CD are collinear.
     */
 
-    double r_top = (A.y - C.y) * (D.x - C.x) - (A.x - C.x) * (D.y - C.y);
-    double r_bot = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);
-    double s_top = (A.y - C.y) * (B.x - A.x) - (A.x - C.x) * (B.y - A.y);
-    double s_bot = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);
+    bool noIntersection = false;
 
-    if((r_bot == 0) || (s_bot == 0)) {
-        return std::min(pointToSegment(A, C, D),
-                        std::min(pointToSegment(B, C, D),
-                                 std::min(pointToSegment(C, A, B), pointToSegment(D, A, B))));
-    }
+    if (!geom::Envelope::intersects(A, B, C, D)) {
+        noIntersection = true;
+    } else {
+        double denom = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);
 
-    double s = s_top / s_bot;
-    double r = r_top / r_bot;
+        if (denom == 0) {
+            noIntersection = true;
+        } else {
+            double r_num = (A.y - C.y) * (D.x - C.x) - (A.x - C.x) * (D.y - C.y);
+            double s_num = (A.y - C.y) * (B.x - A.x) - (A.x - C.x) * (B.y - A.y);
+
+            double s = s_num / denom;
+            double r = r_num / denom;
+
+            if ((r < 0) || (r > 1) || (s < 0) || (s > 1)) {
+                noIntersection = true;
+            }
+        }
+    }
 
-    if((r < 0) || (r > 1) || (s < 0) || (s > 1)) {
+    if (noIntersection) {
         /* no intersection */
         return std::min(pointToSegment(A, C, D),
                         std::min(pointToSegment(B, C, D),
diff --git a/tests/unit/operation/distance/DistanceOpTest.cpp b/tests/unit/operation/distance/DistanceOpTest.cpp
index b7893ff..342a310 100644
--- a/tests/unit/operation/distance/DistanceOpTest.cpp
+++ b/tests/unit/operation/distance/DistanceOpTest.cpp
@@ -554,6 +554,17 @@ void object::test<20>()
     ensure(geos::geom::LineSegment(b0, b1).distance(seq->getAt(1)) < 1e-8);
 }
 
+// JTS testDisjointCollinearSegments
+template<>
+template<>
+void object::test<21>()
+{
+    auto g1 = wktreader.read("LINESTRING (0.0 0.0, 9.9 1.4)");
+    auto g2 = wktreader.read("LINESTRING (11.88 1.68, 21.78 3.08)");
+
+    ensure_equals(g1->distance(g2.get()), 1.9996999774966246);
+}
+
 // TODO: finish the tests by adding:
 // 	LINESTRING - *all*
 // 	MULTILINESTRING - *all*

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

Summary of changes:
 src/algorithm/Distance.cpp                       | 33 +++++++++++++++---------
 tests/unit/operation/distance/DistanceOpTest.cpp | 11 ++++++++
 2 files changed, 32 insertions(+), 12 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list