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

git at osgeo.org git at osgeo.org
Wed May 29 17:43:25 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  ac513373934160f079de7cd34aad8e104ec7f756 (commit)
      from  a4dd9a1a8f7607a9543de636c09b4bc9900a6f67 (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 ac513373934160f079de7cd34aad8e104ec7f756
Author: Daniel Baston <dbaston at gmail.com>
Date:   Tue May 28 15:44:37 2019 -0400

    Remove CoordinateSequence::deleteAt
    
    Having a deleteAt method in the CoordinateSequence interface requires
    that all CoordinateSequence implementations be resizable, which greatly
    limits the scope of possible implementations. The deleteAt method is only
    used in two locations (one of them very inefficiently), so nothing is
    lost by removing it.

diff --git a/include/geos/geom/CoordinateArraySequence.h b/include/geos/geom/CoordinateArraySequence.h
index 7ce2799..67fdf12 100644
--- a/include/geos/geom/CoordinateArraySequence.h
+++ b/include/geos/geom/CoordinateArraySequence.h
@@ -43,13 +43,11 @@ public:
 
     std::unique_ptr<CoordinateSequence> clone() const override;
 
-    //const Coordinate& getCoordinate(int pos) const;
     const Coordinate& getAt(std::size_t pos) const override;
 
     /// Copy Coordinate at position i to Coordinate c
     void getAt(std::size_t i, Coordinate& c) const override;
 
-    //int size() const;
     size_t getSize() const override;
 
     // See dox in CoordinateSequence.h
@@ -105,8 +103,6 @@ public:
 
     void setAt(const Coordinate& c, std::size_t pos) override;
 
-    void deleteAt(std::size_t pos) override;
-
     std::string toString() const override;
 
     void setPoints(const std::vector<Coordinate>& v) override;
diff --git a/include/geos/geom/CoordinateSequence.h b/include/geos/geom/CoordinateSequence.h
index 70eb4c4..230492a 100644
--- a/include/geos/geom/CoordinateSequence.h
+++ b/include/geos/geom/CoordinateSequence.h
@@ -181,9 +181,6 @@ public:
     /// Copy Coordinate c to position pos
     virtual	void setAt(const Coordinate& c, std::size_t pos) = 0;
 
-    /// Delete Coordinate at position pos (list will shrink).
-    virtual	void deleteAt(std::size_t pos) = 0;
-
     /// Get a string representation of CoordinateSequence
     virtual	std::string toString() const = 0;
 
@@ -209,13 +206,6 @@ public:
     static CoordinateSequence* atLeastNCoordinatesOrNothing(std::size_t n,
             CoordinateSequence* c);
 
-    /** \brief
-     *  Returns lower-left Coordinate in given CoordinateSequence.
-     *  This is actually the Coordinate with lower X (and Y if needed)
-     *  ordinate.
-     */
-    static const Coordinate* minCoordinate(CoordinateSequence* cl);
-
     /// Return position of a Coordinate, or -1 if not found
     //
     /// FIXME: return std::size_t, using numeric_limits<std::size_t>::max
diff --git a/src/geom/CoordinateArraySequence.cpp b/src/geom/CoordinateArraySequence.cpp
index 48f068c..78f233d 100644
--- a/src/geom/CoordinateArraySequence.cpp
+++ b/src/geom/CoordinateArraySequence.cpp
@@ -182,12 +182,6 @@ CoordinateArraySequence::setAt(const Coordinate& c, size_t pos)
     (*vect)[pos] = c;
 }
 
-void
-CoordinateArraySequence::deleteAt(size_t pos)
-{
-    vect->erase(vect->begin() + pos);
-}
-
 string
 CoordinateArraySequence::toString() const
 {
diff --git a/src/geom/CoordinateSequence.cpp b/src/geom/CoordinateSequence.cpp
index 847d347..9e9e244 100644
--- a/src/geom/CoordinateSequence.cpp
+++ b/src/geom/CoordinateSequence.cpp
@@ -90,19 +90,6 @@ CoordinateSequence::minCoordinate() const
     return minCoord;
 }
 
-const Coordinate*
-CoordinateSequence::minCoordinate(CoordinateSequence* cl)
-{
-    const Coordinate* minCoord = nullptr;
-    const std::size_t p_size = cl->getSize();
-    for(std::size_t i = 0; i < p_size; i++) {
-        if(minCoord == nullptr || minCoord->compareTo(cl->getAt(i)) > 0) {
-            minCoord = &(cl->getAt(i));
-        }
-    }
-    return minCoord;
-}
-
 size_t
 CoordinateSequence::indexOf(const Coordinate* coordinate,
                             const CoordinateSequence* cl)
@@ -218,14 +205,6 @@ CoordinateSequence::add(const Coordinate& c, bool allowRepeated)
     add(c);
 }
 
-/* Here for backward compatibility */
-//void
-//CoordinateSequence::add(CoordinateSequence *cl, bool allowRepeated,
-//		bool direction)
-//{
-//	add(cl, allowRepeated, direction);
-//}
-
 /*public*/
 void
 CoordinateSequence::add(const CoordinateSequence* cl,
@@ -247,27 +226,6 @@ CoordinateSequence::add(const CoordinateSequence* cl,
 }
 
 
-/*public static*/
-//CoordinateSequence*
-//CoordinateSequence::removeRepeatedPoints(const CoordinateSequence* cl)
-//{
-//#if PROFILE
-//    static Profile* prof = profiler->get("CoordinateSequence::removeRepeatedPoints()");
-//    prof->start();
-//#endif
-//    const vector<Coordinate>* v = cl->toVector();
-//
-//    vector<Coordinate>* nv = new vector<Coordinate>;
-//    nv->reserve(v->size());
-//    unique_copy(v->begin(), v->end(), back_inserter(*nv));
-//    CoordinateSequence* ret = CoordinateArraySequenceFactory::instance()->create(nv);
-//
-//#if PROFILE
-//    prof->stop();
-//#endif
-//    return ret;
-//}
-
 void
 CoordinateSequence::expandEnvelope(Envelope& env) const
 {
diff --git a/src/geom/Polygon.cpp b/src/geom/Polygon.cpp
index fae5f20..779f46b 100644
--- a/src/geom/Polygon.cpp
+++ b/src/geom/Polygon.cpp
@@ -331,9 +331,16 @@ Polygon::normalize(LinearRing* ring, bool clockwise)
     if(ring->isEmpty()) {
         return;
     }
-    auto uniqueCoordinates = ring->getCoordinates();
-    uniqueCoordinates->deleteAt(uniqueCoordinates->getSize() - 1);
-    const Coordinate* minCoordinate = CoordinateSequence::minCoordinate(uniqueCoordinates.get());
+
+    auto seqFactory = ring->getFactory()->getCoordinateSequenceFactory();
+
+    std::unique_ptr<std::vector<Coordinate>> coords(new std::vector<Coordinate>());
+    ring->getCoordinatesRO()->toVector(*coords);
+    coords->erase(coords->end() - 1); // remove last point (repeated)
+
+    std::unique_ptr<CoordinateSequence> uniqueCoordinates = seqFactory->create(coords.release());
+    const Coordinate* minCoordinate = uniqueCoordinates->minCoordinate();
+
     CoordinateSequence::scroll(uniqueCoordinates.get(), minCoordinate);
     uniqueCoordinates->add(uniqueCoordinates->getAt(0));
     if(algorithm::Orientation::isCCW(uniqueCoordinates.get()) == clockwise) {
diff --git a/src/operation/buffer/BufferBuilder.cpp b/src/operation/buffer/BufferBuilder.cpp
index 1f2c653..e35a0c2 100644
--- a/src/operation/buffer/BufferBuilder.cpp
+++ b/src/operation/buffer/BufferBuilder.cpp
@@ -19,6 +19,7 @@
  *
  **********************************************************************/
 
+#include <geos/geom/CoordinateSequenceFactory.h>
 #include <geos/geom/GeometryFactory.h>
 #include <geos/geom/Location.h>
 #include <geos/geom/Geometry.h>
@@ -279,53 +280,71 @@ BufferBuilder::bufferLineSingleSided(const Geometry* g, double distance,
             // epsilon is removed.
             const double segLengthAllowance = 1.02 * distance;
 
+            size_t front = 0;
+            size_t back = coords->size() - 1;
+            size_t sz = back - front + 1;
+
             // Clean up the front of the list.
             // Loop until the line's end is not inside the buffer width from
             // the startPoint.
-            while(coords->size() > 1 &&
-                    coords->front().distance(startPoint) < ptDistAllowance) {
+            while (sz > 1 && coords->getAt(front).distance(startPoint) < ptDistAllowance) {
                 // Record the end segment length.
-                double segLength = coords->front().distance((*coords)[1]);
+                double segLength = coords->getAt(front).distance(coords->getAt(front + 1));
+
                 // Stop looping if there are no more points, or if the segment
                 // length is larger than the buffer width.
-                if(coords->size() <= 1 || segLength > segLengthAllowance) {
+                if(sz <= 1 || segLength > segLengthAllowance) {
                     break;
                 }
+
                 // If the first point is less than buffer width away from the
                 // reference point, then delete the point.
-                coords->deleteAt(0);
+                front++;
+                sz--;
             }
-            while(coords->size() > 1 &&
-                    coords->front().distance(endPoint) < ptDistAllowance) {
-                double segLength = coords->front().distance((*coords)[1]);
-                if(coords->size() <= 1 || segLength > segLengthAllowance) {
+            while(sz > 1 && coords->getAt(front).distance(endPoint) < ptDistAllowance) {
+                double segLength = coords->getAt(front).distance(coords->getAt(front + 1));
+                if(sz <= 1 || segLength > segLengthAllowance) {
                     break;
                 }
-                coords->deleteAt(0);
+                front++;
+                sz--;
             }
-
             // Clean up the back of the list.
-            while(coords->size() > 1 &&
-                    coords->back().distance(startPoint) < ptDistAllowance) {
-                double segLength = coords->back().distance(
-                                       (*coords)[coords->size() - 2]);
-                if(coords->size() <= 1 || segLength > segLengthAllowance) {
+            while(sz > 1 && coords->getAt(back).distance(startPoint) < ptDistAllowance) {
+                double segLength = coords->getAt(back).distance(coords->getAt(back - 1));
+
+                if(sz <= 1 || segLength > segLengthAllowance) {
                     break;
                 }
-                coords->deleteAt(coords->size() - 1);
+                back--;
+                sz--;
             }
-            while(coords->size() > 1 &&
-                    coords->back().distance(endPoint) < ptDistAllowance) {
-                double segLength = coords->back().distance(
-                                       (*coords)[coords->size() - 2]);
-                if(coords->size() <= 1 || segLength > segLengthAllowance) {
+            while(sz > 1 && coords->getAt(back).distance(endPoint) < ptDistAllowance) {
+                double segLength = coords->getAt(back).distance(coords->getAt(back - 1));
+
+                if(sz <= 1 || segLength > segLengthAllowance) {
                     break;
                 }
-                coords->deleteAt(coords->size() - 1);
+                back--;
+                sz--;
             }
 
-            // Add the coordinates to the resultant line string.
-            if(coords->size() > 1) {
+            if (sz > 1) {
+                if (sz < coords->size()) {
+                    // Points were removed; make a new CoordinateSequence
+                    auto seqFactory = geomFact->getCoordinateSequenceFactory();
+
+                    auto newSeq = seqFactory->create(sz, coords->getDimension());
+
+                    for (size_t i = 0; i < sz; i++) {
+                        newSeq->setAt(coords->getAt(i + front), i);
+                    }
+
+                    coords = std::move(newSeq);
+                }
+
+                // Add the coordinates to the resultant line string.
                 mergedLinesGeom->push_back(geomFact->createLineString(coords.release()));
             }
         }
diff --git a/tests/unit/geom/CoordinateArraySequenceTest.cpp b/tests/unit/geom/CoordinateArraySequenceTest.cpp
index fdb42b7..9d6f4eb 100644
--- a/tests/unit/geom/CoordinateArraySequenceTest.cpp
+++ b/tests/unit/geom/CoordinateArraySequenceTest.cpp
@@ -315,53 +315,6 @@ void object::test<8>
     ensure(!sequence.hasRepeatedPoints());
 }
 
-// Test of deleteAt()
-template<>
-template<>
-void object::test<9>
-()
-{
-    using geos::geom::Coordinate;
-
-    // Create sequence with only 1 default coordinate
-    const size_t sizeOne = 1;
-    geos::geom::CoordinateArraySequence sequence(1);
-
-    ensure(!sequence.isEmpty());
-    ensure_equals(sequence.size(), sizeOne);
-
-    // Delete the only coordinate in the sequence
-    sequence.deleteAt(0);
-    const size_t sizeZero = 0;
-
-    ensure(sequence.isEmpty());
-    ensure_equals(sequence.size(), sizeZero);
-
-    // Add new 3 coordinates
-    Coordinate first(1, 2, 3);
-    sequence.add(first);
-    Coordinate second(5, 10, 15);
-    sequence.add(second);
-    Coordinate third(9, 18, 27);
-    sequence.add(third);
-    const size_t sizeThree = 3;
-
-    ensure(!sequence.isEmpty());
-    ensure_equals(sequence.size(), sizeThree);
-
-    // Delete coordinate in the middle of sequence - the second one.
-    sequence.deleteAt(1); // (5, 10, 15)
-    const size_t sizeTwo = 2;
-
-    ensure(!sequence.isEmpty());
-    ensure_equals(sequence.size(), sizeTwo);
-
-    ensure(sequence.getAt(0) != sequence.getAt(1));
-    ensure_equals(sequence.getAt(0), first);
-    ensure("deleteAt() did not remove coordinate.", sequence.getAt(1) != second);
-    ensure_equals(sequence.getAt(1), third);
-}
-
 // Test of setPoints()
 template<>
 template<>

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

Summary of changes:
 include/geos/geom/CoordinateArraySequence.h     |  4 --
 include/geos/geom/CoordinateSequence.h          | 10 ----
 src/geom/CoordinateArraySequence.cpp            |  6 ---
 src/geom/CoordinateSequence.cpp                 | 42 ---------------
 src/geom/Polygon.cpp                            | 13 +++--
 src/operation/buffer/BufferBuilder.cpp          | 69 ++++++++++++++++---------
 tests/unit/geom/CoordinateArraySequenceTest.cpp | 47 -----------------
 7 files changed, 54 insertions(+), 137 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list