[geos-commits] [SCM] GEOS branch main updated. c2e6895c6aaf49cc12fd84eed2c827ba9cf298df

git at osgeo.org git at osgeo.org
Thu Jun 24 14:32:14 PDT 2021


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, main has been updated
       via  c2e6895c6aaf49cc12fd84eed2c827ba9cf298df (commit)
       via  00a6987f0a52029d3f775a83adbc5be1666b6070 (commit)
       via  66b8577983aac6c79b7a2e971138bd1acc263983 (commit)
      from  6a5566b0dc79e59984c03ddbd21d7c652e773fc1 (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 c2e6895c6aaf49cc12fd84eed2c827ba9cf298df
Merge: 6a5566b 00a6987
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Thu Jun 24 14:32:10 2021 -0700

    Merge branch 'rouault-closestPoint_improvement' into main


commit 00a6987f0a52029d3f775a83adbc5be1666b6070
Merge: 6a5566b 66b8577
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Thu Jun 24 14:31:35 2021 -0700

    Merge branch 'closestPoint_improvement' of https://github.com/rouault/geos into rouault-closestPoint_improvement


commit 66b8577983aac6c79b7a2e971138bd1acc263983
Author: Even Rouault <even.rouault at spatialys.com>
Date:   Thu Jun 17 00:17:11 2021 +0200

    LineSegment: tiny improvement in project(const LineSegment&, ...) and closestPoint()
    
    Those methods already compute the projection factor, but then call
    project() which recomputes it again. Avoid that duplicated computation.
    
    Didn't identify this as a hotspot, but should save a few CPU cycles.

diff --git a/include/geos/geom/LineSegment.h b/include/geos/geom/LineSegment.h
index f19af03..1d78f7e 100644
--- a/include/geos/geom/LineSegment.h
+++ b/include/geos/geom/LineSegment.h
@@ -369,6 +369,10 @@ public:
             return h ^ (std::hash<double>{}(s.p1.y) << 1);
         }
     };
+
+private:
+    void project(double factor, Coordinate& ret) const;
+
 };
 
 std::ostream& operator<< (std::ostream& o, const LineSegment& l);
diff --git a/src/geom/LineSegment.cpp b/src/geom/LineSegment.cpp
index 04773fe..0d17fdd 100644
--- a/src/geom/LineSegment.cpp
+++ b/src/geom/LineSegment.cpp
@@ -105,6 +105,16 @@ LineSegment::project(const Coordinate& p, Coordinate& ret) const
     ret = Coordinate(p0.x + r * (p1.x - p0.x), p0.y + r * (p1.y - p0.y));
 }
 
+/*private*/
+void
+LineSegment::project(double factor, Coordinate& ret) const
+{
+    if( factor == 1.0 )
+        ret = p1;
+    else
+        ret = Coordinate(p0.x + factor * (p1.x - p0.x), p0.y + factor * (p1.y - p0.y));
+}
+
 bool
 LineSegment::project(const LineSegment& seg, LineSegment& ret) const
 {
@@ -121,9 +131,9 @@ LineSegment::project(const LineSegment& seg, LineSegment& ret) const
     }
 
     Coordinate newp0;
-    project(seg.p0, newp0);
+    project(pf0, newp0);
     Coordinate newp1;
-    project(seg.p1, newp1);
+    project(pf1, newp1);
 
     ret.setCoordinates(newp0, newp1);
 
@@ -136,7 +146,7 @@ LineSegment::closestPoint(const Coordinate& p, Coordinate& ret) const
 {
     double factor = projectionFactor(p);
     if(factor > 0 && factor < 1) {
-        project(p, ret);
+        project(factor, ret);
         return;
     }
     double dist0 = p0.distance(p);

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

Summary of changes:
 include/geos/geom/LineSegment.h |  4 ++++
 src/geom/LineSegment.cpp        | 16 +++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list