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

git at osgeo.org git at osgeo.org
Sat Mar 6 10:57:38 PST 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, master has been updated
       via  d2482e91dd35ebbf3f992e5338809d44767a0340 (commit)
      from  60dda910dc31171d4919025bc489687b36766aa9 (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 d2482e91dd35ebbf3f992e5338809d44767a0340
Author: Daniel Baston <dbaston at gmail.com>
Date:   Fri Feb 19 12:01:39 2021 -0500

    Avoid vector use in MonotoneChain index queries, mark methods const

diff --git a/include/geos/index/chain/MonotoneChain.h b/include/geos/index/chain/MonotoneChain.h
index d71cd2e..8c59c6e 100644
--- a/include/geos/index/chain/MonotoneChain.h
+++ b/include/geos/index/chain/MonotoneChain.h
@@ -102,8 +102,8 @@ public:
     ~MonotoneChain() = default;
 
     /// Returned envelope is owned by this class
-    const geom::Envelope& getEnvelope();
-    const geom::Envelope& getEnvelope(double expansionDistance);
+    const geom::Envelope& getEnvelope() const;
+    const geom::Envelope& getEnvelope(double expansionDistance) const;
 
     size_t
     getStartIndex() const
@@ -122,8 +122,8 @@ public:
      *  at the given index.
      */
     void getLineSegment(std::size_t index, geom::LineSegment& ls) const {
-        ls.p0 = pts[index];
-        ls.p1 = pts[index + 1];
+        pts->getAt(index, ls.p0);
+        pts->getAt(index + 1, ls.p1);
     }
 
     /**
@@ -138,16 +138,16 @@ public:
      * the searchEnvelope, and process them
      */
     void select(const geom::Envelope& searchEnv,
-                MonotoneChainSelectAction& mcs);
+                MonotoneChainSelectAction& mcs) const;
 
-    void computeOverlaps(MonotoneChain* mc,
-                         MonotoneChainOverlapAction* mco);
+    void computeOverlaps(const MonotoneChain* mc,
+                         MonotoneChainOverlapAction* mco) const;
 
-    void computeOverlaps(MonotoneChain* mc, double overlapTolerance,
-                         MonotoneChainOverlapAction* mco);
+    void computeOverlaps(const MonotoneChain* mc, double overlapTolerance,
+                         MonotoneChainOverlapAction* mco) const;
 
     void*
-    getContext()
+    getContext() const
     {
         return context;
     }
@@ -157,29 +157,30 @@ private:
     void computeSelect(const geom::Envelope& searchEnv,
                        std::size_t start0,
                        std::size_t end0,
-                       MonotoneChainSelectAction& mcs);
+                       MonotoneChainSelectAction& mcs) const;
 
-    void computeOverlaps(std::size_t start0, std::size_t end0, MonotoneChain& mc,
+    void computeOverlaps(std::size_t start0, std::size_t end0, const MonotoneChain& mc,
                          std::size_t start1, std::size_t end1,
                          double overlapTolerance,
-                         MonotoneChainOverlapAction& mco);
+                         MonotoneChainOverlapAction& mco) const;
 
     bool overlaps(std::size_t start0, std::size_t end0,
                   const MonotoneChain& mc, std::size_t start1, std::size_t end1,
                   double overlapTolerance) const {
         if (overlapTolerance > 0.0) {
-            return overlaps(pts[start0], pts[end0], mc.pts[start1], mc.pts[end1], overlapTolerance);
+            return overlaps(pts->getAt(start0), pts->getAt(end0),
+                            mc.pts->getAt(start1), mc.pts->getAt(end1), overlapTolerance);
         }
-        return geom::Envelope::intersects(pts.getAt(start0), pts.getAt(end0),
-                                          mc.pts.getAt(start1), mc.pts.getAt(end1));
+        return geom::Envelope::intersects(pts->getAt(start0), pts->getAt(end0),
+                                          mc.pts->getAt(start1), mc.pts->getAt(end1));
     }
 
-    bool overlaps(const geom::Coordinate& p1, const geom::Coordinate& p2,
+    static bool overlaps(const geom::Coordinate& p1, const geom::Coordinate& p2,
                   const geom::Coordinate& q1, const geom::Coordinate& q2,
-                  double overlapTolerance) const;
+                  double overlapTolerance);
 
     /// Externally owned
-    const geom::CoordinateSequence& pts;
+    const geom::CoordinateSequence* pts;
 
     /// user-defined information
     void* context;
@@ -191,12 +192,7 @@ private:
     std::size_t end;
 
     /// Owned by this class
-    geom::Envelope env;
-
-    // Declare type as noncopyable
-    // XXXXXX uncomment for MSVC support
-    // MonotoneChain(const MonotoneChain& other) = delete;
-    // MonotoneChain& operator=(const MonotoneChain& rhs) = delete;
+    mutable geom::Envelope env;
 };
 
 } // namespace geos::index::chain
diff --git a/include/geos/index/chain/MonotoneChainOverlapAction.h b/include/geos/index/chain/MonotoneChainOverlapAction.h
index bfafc82..dadd204 100644
--- a/include/geos/index/chain/MonotoneChainOverlapAction.h
+++ b/include/geos/index/chain/MonotoneChainOverlapAction.h
@@ -65,8 +65,8 @@ public:
      * @param start2 the index of the start of the overlapping segment
      *               from mc2
      */
-    virtual void overlap(MonotoneChain& mc1, std::size_t start1,
-                         MonotoneChain& mc2, std::size_t start2);
+    virtual void overlap(const MonotoneChain& mc1, std::size_t start1,
+                         const MonotoneChain& mc2, std::size_t start2);
 
     /** \brief
      * This is a convenience function which can be overridden to
@@ -77,8 +77,7 @@ public:
      */
     virtual void
     overlap(const geom::LineSegment& /*seg1*/,
-            const geom::LineSegment& /*seg2*/)
-    {}
+            const geom::LineSegment& /*seg2*/) {}
 
 };
 
diff --git a/include/geos/index/chain/MonotoneChainSelectAction.h b/include/geos/index/chain/MonotoneChainSelectAction.h
index 5e747a1..3e8d175 100644
--- a/include/geos/index/chain/MonotoneChainSelectAction.h
+++ b/include/geos/index/chain/MonotoneChainSelectAction.h
@@ -56,7 +56,7 @@ public:
     ~MonotoneChainSelectAction() {}
 
     /// This function can be overridden if the original chain is needed
-    virtual void select(MonotoneChain& mc, std::size_t start);
+    virtual void select(const MonotoneChain& mc, std::size_t start);
 
     /**
      * This is a convenience function which can be overridden
diff --git a/include/geos/noding/MCIndexNoder.h b/include/geos/noding/MCIndexNoder.h
index f8c76c1..7ebe12f 100644
--- a/include/geos/noding/MCIndexNoder.h
+++ b/include/geos/noding/MCIndexNoder.h
@@ -67,7 +67,7 @@ class GEOS_DLL MCIndexNoder : public SinglePassNoder {
 
 private:
     std::vector<index::chain::MonotoneChain> monoChains;
-    index::strtree::TemplateSTRtree<index::chain::MonotoneChain*> index;
+    index::strtree::TemplateSTRtree<const index::chain::MonotoneChain*> index;
     std::vector<SegmentString*>* nodedSegStrings;
     // statistics
     int nOverlaps;
@@ -112,8 +112,8 @@ public:
             si(newSi)
         {}
 
-        void overlap(index::chain::MonotoneChain& mc1, std::size_t start1,
-                     index::chain::MonotoneChain& mc2, std::size_t start2) override;
+        void overlap(const index::chain::MonotoneChain& mc1, std::size_t start1,
+                     const index::chain::MonotoneChain& mc2, std::size_t start2) override;
     private:
         SegmentIntersector& si;
 
diff --git a/include/geos/noding/MCIndexSegmentSetMutualIntersector.h b/include/geos/noding/MCIndexSegmentSetMutualIntersector.h
index 2f4b348..16772af 100644
--- a/include/geos/noding/MCIndexSegmentSetMutualIntersector.h
+++ b/include/geos/noding/MCIndexSegmentSetMutualIntersector.h
@@ -91,8 +91,8 @@ public:
             index::chain::MonotoneChainOverlapAction(), si(p_si)
         {}
 
-        void overlap(index::chain::MonotoneChain& mc1, std::size_t start1,
-                     index::chain::MonotoneChain& mc2, std::size_t start2) override;
+        void overlap(const index::chain::MonotoneChain& mc1, std::size_t start1,
+                     const index::chain::MonotoneChain& mc2, std::size_t start2) override;
     };
 
     /**
@@ -112,7 +112,7 @@ private:
      * envelope (range) queries efficiently (such as a index::quadtree::Quadtree
      * or index::strtree::STRtree).
      */
-    index::strtree::TemplateSTRtree<index::chain::MonotoneChain*> index;
+    index::strtree::TemplateSTRtree<const index::chain::MonotoneChain*> index;
     int indexCounter;
     int processCounter;
     // statistics
diff --git a/include/geos/noding/SegmentSetMutualIntersector.h b/include/geos/noding/SegmentSetMutualIntersector.h
index 56e9714..d12b988 100644
--- a/include/geos/noding/SegmentSetMutualIntersector.h
+++ b/include/geos/noding/SegmentSetMutualIntersector.h
@@ -46,7 +46,7 @@ public:
 
     /**
      * Sets the SegmentIntersector to use with this intersector.
-     * The SegmentIntersector will either rocord or add intersection nodes
+     * The SegmentIntersector will either record or add intersection nodes
      * for the input segment strings.
      *
      * @param si the segment intersector to use
diff --git a/src/index/chain/MonotoneChain.cpp b/src/index/chain/MonotoneChain.cpp
index 0c364a9..342b579 100644
--- a/src/index/chain/MonotoneChain.cpp
+++ b/src/index/chain/MonotoneChain.cpp
@@ -33,7 +33,7 @@ namespace chain { // geos.index.chain
 
 MonotoneChain::MonotoneChain(const geom::CoordinateSequence& newPts,
                              std::size_t nstart, std::size_t nend, void* nContext)
-    : pts(newPts)
+    : pts(&newPts)
     , context(nContext)
     , start(nstart)
     , end(nend)
@@ -41,16 +41,16 @@ MonotoneChain::MonotoneChain(const geom::CoordinateSequence& newPts,
 {}
 
 const Envelope&
-MonotoneChain::getEnvelope()
+MonotoneChain::getEnvelope() const
 {
     return getEnvelope(0.0);
 }
 
 const Envelope&
-MonotoneChain::getEnvelope(double expansionDistance)
+MonotoneChain::getEnvelope(double expansionDistance) const
 {
     if (env.isNull()) {
-        env.init(pts[start], pts[end]);
+        env.init(pts->getAt(start), pts->getAt(end));
         if (expansionDistance > 0.0) {
             env.expandBy(expansionDistance);
         }
@@ -61,11 +61,11 @@ MonotoneChain::getEnvelope(double expansionDistance)
 std::unique_ptr<CoordinateSequence>
 MonotoneChain::getCoordinates() const
 {
-    return std::unique_ptr<CoordinateSequence>(pts.clone());
+    return pts->clone();
 }
 
 void
-MonotoneChain::select(const Envelope& searchEnv, MonotoneChainSelectAction& mcs)
+MonotoneChain::select(const Envelope& searchEnv, MonotoneChainSelectAction& mcs) const
 {
     computeSelect(searchEnv, start, end, mcs);
 }
@@ -73,10 +73,10 @@ MonotoneChain::select(const Envelope& searchEnv, MonotoneChainSelectAction& mcs)
 void
 MonotoneChain::computeSelect(const Envelope& searchEnv,
                              std::size_t start0, std::size_t end0,
-                             MonotoneChainSelectAction& mcs)
+                             MonotoneChainSelectAction& mcs) const
 {
-    const Coordinate& p0 = pts[start0];
-    const Coordinate& p1 = pts[end0];
+    const Coordinate& p0 = pts->getAt(start0);
+    const Coordinate& p1 = pts->getAt(end0);
 
     // terminating condition for the recursion
     if(end0 - start0 == 1) {
@@ -103,16 +103,16 @@ MonotoneChain::computeSelect(const Envelope& searchEnv,
 
 /* public */
 void
-MonotoneChain::computeOverlaps(MonotoneChain* mc,
-                               MonotoneChainOverlapAction* mco)
+MonotoneChain::computeOverlaps(const MonotoneChain* mc,
+                               MonotoneChainOverlapAction* mco) const
 {
     computeOverlaps(start, end, *mc, mc->start, mc->end, 0.0, *mco);
 }
 
 /* public */
 void
-MonotoneChain::computeOverlaps(MonotoneChain* mc, double overlapTolerance,
-                               MonotoneChainOverlapAction* mco)
+MonotoneChain::computeOverlaps(const MonotoneChain* mc, double overlapTolerance,
+                               MonotoneChainOverlapAction* mco) const
 {
     computeOverlaps(start, end, *mc, mc->start, mc->end, overlapTolerance, *mco);
 }
@@ -120,10 +120,10 @@ MonotoneChain::computeOverlaps(MonotoneChain* mc, double overlapTolerance,
 /*private*/
 void
 MonotoneChain::computeOverlaps(std::size_t start0, std::size_t end0,
-                               MonotoneChain& mc,
+                               const MonotoneChain& mc,
                                std::size_t start1, std::size_t end1,
                                double overlapTolerance,
-                               MonotoneChainOverlapAction& mco)
+                               MonotoneChainOverlapAction& mco) const
 {
     // terminating condition for the recursion
     if(end0 - start0 == 1 && end1 - start1 == 1) {
@@ -166,7 +166,7 @@ MonotoneChain::computeOverlaps(std::size_t start0, std::size_t end0,
 bool
 MonotoneChain::overlaps(const Coordinate& p1, const Coordinate& p2,
                         const Coordinate& q1, const Coordinate& q2,
-                        double overlapTolerance) const
+                        double overlapTolerance)
 {
     double maxq = std::max(q1.x, q2.x);
     double minp = std::min(p1.x, p2.x);
diff --git a/src/index/chain/MonotoneChainOverlapAction.cpp b/src/index/chain/MonotoneChainOverlapAction.cpp
index 2d73a40..76f0ece 100644
--- a/src/index/chain/MonotoneChainOverlapAction.cpp
+++ b/src/index/chain/MonotoneChainOverlapAction.cpp
@@ -29,8 +29,8 @@ namespace index { // geos.index
 namespace chain { // geos.index.chain
 
 void
-MonotoneChainOverlapAction::overlap(MonotoneChain& mc1, std::size_t start1,
-                                    MonotoneChain& mc2, std::size_t start2)
+MonotoneChainOverlapAction::overlap(const MonotoneChain& mc1, std::size_t start1,
+                                    const MonotoneChain& mc2, std::size_t start2)
 {
     mc1.getLineSegment(start1, overlapSeg1);
     mc2.getLineSegment(start2, overlapSeg2);
diff --git a/src/index/chain/MonotoneChainSelectAction.cpp b/src/index/chain/MonotoneChainSelectAction.cpp
index d79ea23..6bcf0f3 100644
--- a/src/index/chain/MonotoneChainSelectAction.cpp
+++ b/src/index/chain/MonotoneChainSelectAction.cpp
@@ -28,7 +28,7 @@ namespace index { // geos.index
 namespace chain { // geos.index.chain
 
 void
-MonotoneChainSelectAction::select(MonotoneChain& mc, std::size_t start)
+MonotoneChainSelectAction::select(const MonotoneChain& mc, std::size_t start)
 {
     mc.getLineSegment(start, selectedSegment);
 
diff --git a/src/noding/MCIndexNoder.cpp b/src/noding/MCIndexNoder.cpp
index acb0bbc..18dfe4f 100644
--- a/src/noding/MCIndexNoder.cpp
+++ b/src/noding/MCIndexNoder.cpp
@@ -54,8 +54,8 @@ MCIndexNoder::computeNodes(SegmentString::NonConstVect* inputSegStrings)
     }
 
     if (!indexBuilt) {
-        for(auto& mc : monoChains) {
-            index.insert(&(mc.getEnvelope(overlapTolerance)), &mc);
+        for(const auto& mc : monoChains) {
+            index.insert(mc.getEnvelope(overlapTolerance), &mc);
         }
         indexBuilt = true;
     }
@@ -72,17 +72,11 @@ MCIndexNoder::intersectChains()
 
     SegmentOverlapAction overlapAction(*segInt);
 
-    std::vector<void*> overlapChains;
-    for(MonotoneChain& queryChain : monoChains) {
+    for(const MonotoneChain& queryChain : monoChains) {
         GEOS_CHECK_FOR_INTERRUPTS();
 
-        overlapChains.clear();
         const geom::Envelope& queryEnv = queryChain.getEnvelope(overlapTolerance);
-        index.query(&queryEnv, overlapChains);
-        for(void* hit : overlapChains) {
-            MonotoneChain* testChain = static_cast<MonotoneChain*>(hit);
-            assert(testChain);
-
+        index.query(queryEnv, [&queryChain, &overlapAction, this](const MonotoneChain* testChain) {
             /*
              * following test makes sure we only compare each
              * pair of chains once and that we don't compare a
@@ -93,12 +87,8 @@ MCIndexNoder::intersectChains()
                 nOverlaps++;
             }
 
-            // short-circuit if possible
-            if(segInt->isDone()) {
-                return;
-            }
-
-        }
+            return !segInt->isDone(); // abort early if segInt->isDone()
+        });
     }
 }
 
@@ -116,8 +106,8 @@ MCIndexNoder::add(SegmentString* segStr)
 
 
 void
-MCIndexNoder::SegmentOverlapAction::overlap(MonotoneChain& mc1, std::size_t start1,
-        MonotoneChain& mc2, std::size_t start2)
+MCIndexNoder::SegmentOverlapAction::overlap(const MonotoneChain& mc1, std::size_t start1,
+        const MonotoneChain& mc2, std::size_t start2)
 {
     SegmentString* ss1 = const_cast<SegmentString*>(
                              static_cast<const SegmentString*>(mc1.getContext())
diff --git a/src/noding/MCIndexSegmentSetMutualIntersector.cpp b/src/noding/MCIndexSegmentSetMutualIntersector.cpp
index 5f18e94..a2bb9dd 100644
--- a/src/noding/MCIndexSegmentSetMutualIntersector.cpp
+++ b/src/noding/MCIndexSegmentSetMutualIntersector.cpp
@@ -60,19 +60,13 @@ MCIndexSegmentSetMutualIntersector::intersectChains()
 {
     MCIndexSegmentSetMutualIntersector::SegmentOverlapAction overlapAction(*segInt);
 
-    std::vector<MonotoneChain*> overlapChains;
     for(auto& queryChain : monoChains) {
-        overlapChains.clear();
-
-        index.query(queryChain.getEnvelope(), overlapChains);
-
-        for(MonotoneChain* testChain : overlapChains) {
+        index.query(queryChain.getEnvelope(), [&queryChain, &overlapAction, this](const MonotoneChain* testChain) {
             queryChain.computeOverlaps(testChain, &overlapAction);
             nOverlaps++;
-            if(segInt->isDone()) {
-                return;
-            }
-        }
+
+            return !segInt->isDone(); // abort early if segInt->isDone()
+        });
     }
 }
 
@@ -116,7 +110,7 @@ MCIndexSegmentSetMutualIntersector::process(SegmentString::ConstVect* segStrings
 /* public */
 void
 MCIndexSegmentSetMutualIntersector::SegmentOverlapAction::overlap(
-    MonotoneChain& mc1, std::size_t start1, MonotoneChain& mc2, std::size_t start2)
+    const MonotoneChain& mc1, std::size_t start1, const MonotoneChain& mc2, std::size_t start2)
 {
     SegmentString* ss1 = (SegmentString*)(mc1.getContext());
     SegmentString* ss2 = (SegmentString*)(mc2.getContext());
diff --git a/src/noding/snapround/MCIndexPointSnapper.cpp b/src/noding/snapround/MCIndexPointSnapper.cpp
index 54169e4..74635c4 100644
--- a/src/noding/snapround/MCIndexPointSnapper.cpp
+++ b/src/noding/snapround/MCIndexPointSnapper.cpp
@@ -72,7 +72,7 @@ public:
      * would cause every vertex to be noded).
      */
     void
-    select(chain::MonotoneChain& mc, std::size_t startIndex) override
+    select(const chain::MonotoneChain& mc, std::size_t startIndex) override
     {
         // This is casting away 'constness'!
         NodedSegmentString& ss = *(static_cast<NodedSegmentString*>(mc.getContext()));

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

Summary of changes:
 include/geos/index/chain/MonotoneChain.h           | 46 ++++++++++------------
 .../geos/index/chain/MonotoneChainOverlapAction.h  |  7 ++--
 .../geos/index/chain/MonotoneChainSelectAction.h   |  2 +-
 include/geos/noding/MCIndexNoder.h                 |  6 +--
 .../noding/MCIndexSegmentSetMutualIntersector.h    |  6 +--
 include/geos/noding/SegmentSetMutualIntersector.h  |  2 +-
 src/index/chain/MonotoneChain.cpp                  | 32 +++++++--------
 src/index/chain/MonotoneChainOverlapAction.cpp     |  4 +-
 src/index/chain/MonotoneChainSelectAction.cpp      |  2 +-
 src/noding/MCIndexNoder.cpp                        | 26 ++++--------
 src/noding/MCIndexSegmentSetMutualIntersector.cpp  | 16 +++-----
 src/noding/snapround/MCIndexPointSnapper.cpp       |  2 +-
 12 files changed, 65 insertions(+), 86 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list