[geos-commits] [SCM] GEOS branch master updated. 388953bccc5fe1cb9196b0fd393a14988b8a3d84

git at osgeo.org git at osgeo.org
Fri Nov 8 08:17:12 PST 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  388953bccc5fe1cb9196b0fd393a14988b8a3d84 (commit)
       via  cada197cb59846ae6803f1a90c9cbd573aa79239 (commit)
       via  a8e417b17cd1731cf875e1bfa1a4a8b08369eb60 (commit)
      from  c96422005f1bd2bff98e74f201e4a3a4328c85f2 (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 388953bccc5fe1cb9196b0fd393a14988b8a3d84
Merge: c964220 cada197
Author: Daniel Baston <dbaston at gmail.com>
Date:   Fri Nov 8 11:16:37 2019 -0500

    Merge branch 'trac-1001-alternate'


commit cada197cb59846ae6803f1a90c9cbd573aa79239
Author: Daniel Baston <dbaston at gmail.com>
Date:   Fri Oct 25 15:13:44 2019 -0400

    Distinguish between 2D and 3D empty Points

diff --git a/include/geos/geom/FixedSizeCoordinateSequence.h b/include/geos/geom/FixedSizeCoordinateSequence.h
index 2bdcbb2..20e661d 100644
--- a/include/geos/geom/FixedSizeCoordinateSequence.h
+++ b/include/geos/geom/FixedSizeCoordinateSequence.h
@@ -35,9 +35,9 @@ namespace geom {
         explicit FixedSizeCoordinateSequence(size_t dimension_in = 0) : dimension(dimension_in) {}
 
         std::unique_ptr<CoordinateSequence> clone() const final override {
-            auto seq = detail::make_unique<FixedSizeCoordinateSequence<N>>();
+            auto seq = detail::make_unique<FixedSizeCoordinateSequence<N>>(dimension);
             seq->m_data = m_data;
-            return std::unique_ptr<CoordinateSequence>(seq.release());
+            return std::move(seq); // move needed for gcc 4.8
         }
 
         const Coordinate& getAt(size_t i) const final override {
diff --git a/include/geos/geom/Point.h b/include/geos/geom/Point.h
index a631e70..bc84980 100644
--- a/include/geos/geom/Point.h
+++ b/include/geos/geom/Point.h
@@ -178,7 +178,9 @@ private:
      *  The <code>Coordinate</code> wrapped by this <code>Point</code>.
      */
     FixedSizeCoordinateSequence<1> coordinates;
-    bool empty;
+
+    bool empty2d;
+    bool empty3d;
 };
 
 } // namespace geos::geom
diff --git a/src/geom/Point.cpp b/src/geom/Point.cpp
index 3724503..864e883 100644
--- a/src/geom/Point.cpp
+++ b/src/geom/Point.cpp
@@ -41,18 +41,20 @@ using namespace std;
 namespace geos {
 namespace geom { // geos::geom
 
-const static FixedSizeCoordinateSequence<0> emptyCoords;
+const static FixedSizeCoordinateSequence<0> emptyCoords2d(2);
+const static FixedSizeCoordinateSequence<0> emptyCoords3d(3);
 
 /*protected*/
 Point::Point(CoordinateSequence* newCoords, const GeometryFactory* factory)
     :
     Geometry(factory),
-    empty(false)
+    empty2d(false),
+    empty3d(false)
 {
     std::unique_ptr<CoordinateSequence> coords(newCoords);
 
     if(coords == nullptr) {
-        empty = true;
+        empty3d = true;
         return;
     }
 
@@ -60,14 +62,17 @@ Point::Point(CoordinateSequence* newCoords, const GeometryFactory* factory)
         coordinates.setAt(coords->getAt(0), 0);
     } else if (coords->getSize() > 1) {
         throw util::IllegalArgumentException("Point coordinate list must contain a single element");
+    } else if (coords->getDimension() == 3) {
+        empty3d = true;
     } else {
-        empty = true;
+        empty2d = true;
     }
 }
 
 Point::Point(const Coordinate & c, const GeometryFactory* factory) :
     Geometry(factory),
-    empty(false)
+    empty2d(false),
+    empty3d(false)
 {
     coordinates.setAt(c, 0);
 }
@@ -77,7 +82,8 @@ Point::Point(const Point& p)
     :
     Geometry(p),
     coordinates(p.coordinates),
-    empty(p.empty)
+    empty2d(p.empty3d),
+    empty3d(p.empty3d)
 {
 }
 
@@ -90,13 +96,13 @@ Point::getCoordinates() const
 size_t
 Point::getNumPoints() const
 {
-    return empty ? 0 : 1;
+    return isEmpty() ? 0 : 1;
 }
 
 bool
 Point::isEmpty() const
 {
-    return empty;
+    return empty2d || empty3d;
 }
 
 bool
@@ -153,7 +159,7 @@ Point::getZ() const
 const Coordinate*
 Point::getCoordinate() const
 {
-    return empty ? nullptr : &coordinates[0];
+    return isEmpty() ? nullptr : &coordinates[0];
 }
 
 string
@@ -288,8 +294,10 @@ Point::getGeometryTypeId() const
 const CoordinateSequence*
 Point::getCoordinatesRO() const
 {
-    if (isEmpty()) {
-        return &emptyCoords;
+    if (empty2d) {
+        return &emptyCoords2d;
+    } else if (empty3d) {
+        return &emptyCoords3d;
     }
     return &coordinates;
 }
diff --git a/tests/unit/geom/FixedSizeCoordinateSequenceTest.cpp b/tests/unit/geom/FixedSizeCoordinateSequenceTest.cpp
index 968c733..9987750 100644
--- a/tests/unit/geom/FixedSizeCoordinateSequenceTest.cpp
+++ b/tests/unit/geom/FixedSizeCoordinateSequenceTest.cpp
@@ -124,4 +124,20 @@ void object::test<5>() {
     ensure_equals(seq1_3d.getDimension(), 3ul);
 }
 
+// test clone
+template<>
+template<>
+void object::test<6>
+()
+{
+    FixedSizeCoordinateSequence<1> a(2);
+    a.setAt({ 1, 2, 3 }, 0);
+
+    ensure_equals(a.getDimension(), 2);
+
+    auto b = a.clone();
+    ensure_equals(b->getDimension(), 2);
+    ensure(a.getAt(0).equals3D(b->getAt(0)));
+}
+
 }
diff --git a/tests/unit/geom/PointTest.cpp b/tests/unit/geom/PointTest.cpp
index 883ad7b..67f085c 100644
--- a/tests/unit/geom/PointTest.cpp
+++ b/tests/unit/geom/PointTest.cpp
@@ -559,5 +559,26 @@ void object::test<44>
     ensure_equals(empty_point_->getCoordinatesRO()->getSize(), 0u);
 }
 
+// check dimensionality of empty points
+template<>
+template<>
+void object::test<45>
+()
+{
+    auto empty3d = factory_->createPoint();
+    ensure_equals(empty3d->getCoordinateDimension(), 3);
+
+    geos::geom::FixedSizeCoordinateSequence<0> seq2(2);
+    ensure_equals(seq2.getDimension(), 2u);
+    ensure_equals(factory_->createPoint(seq2)->getCoordinateDimension(), 2);
+
+    geos::geom::FixedSizeCoordinateSequence<0> seq3(3);
+    ensure_equals(seq3.getDimension(), 3u);
+    ensure_equals(factory_->createPoint(seq3)->getCoordinateDimension(), 3);
+
+
+
+}
+
 } // namespace tut
 

commit a8e417b17cd1731cf875e1bfa1a4a8b08369eb60
Author: Daniel Baston <dbaston at gmail.com>
Date:   Wed Oct 23 21:25:39 2019 -0400

    Avoid returning size-1 CoordinateSequence from empty point
    
    Fixes #1001

diff --git a/src/geom/Point.cpp b/src/geom/Point.cpp
index 0db6b30..3724503 100644
--- a/src/geom/Point.cpp
+++ b/src/geom/Point.cpp
@@ -41,6 +41,7 @@ using namespace std;
 namespace geos {
 namespace geom { // geos::geom
 
+const static FixedSizeCoordinateSequence<0> emptyCoords;
 
 /*protected*/
 Point::Point(CoordinateSequence* newCoords, const GeometryFactory* factory)
@@ -83,7 +84,7 @@ Point::Point(const Point& p)
 std::unique_ptr<CoordinateSequence>
 Point::getCoordinates() const
 {
-    return coordinates.clone();
+    return getCoordinatesRO()->clone();
 }
 
 size_t
@@ -113,7 +114,7 @@ Point::getDimension() const
 int
 Point::getCoordinateDimension() const
 {
-    return (int) coordinates.getDimension();
+    return (int) getCoordinatesRO()->getDimension();
 }
 
 int
@@ -191,6 +192,9 @@ Point::apply_ro(CoordinateFilter* filter) const
 void
 Point::apply_rw(const CoordinateFilter* filter)
 {
+    if (isEmpty()) {
+        return;
+    }
     coordinates.apply_rw(filter);
 }
 
@@ -284,6 +288,9 @@ Point::getGeometryTypeId() const
 const CoordinateSequence*
 Point::getCoordinatesRO() const
 {
+    if (isEmpty()) {
+        return &emptyCoords;
+    }
     return &coordinates;
 }
 
diff --git a/tests/unit/geom/PointTest.cpp b/tests/unit/geom/PointTest.cpp
index 4a91875..883ad7b 100644
--- a/tests/unit/geom/PointTest.cpp
+++ b/tests/unit/geom/PointTest.cpp
@@ -549,5 +549,15 @@ void object::test<43>
     ensure(!point_->isDimensionStrict(geos::geom::Dimension::A));
 }
 
+// empty point has size-0 coordinate sequence
+template<>
+template<>
+void object::test<44>
+()
+{
+    ensure_equals(empty_point_->getCoordinates()->getSize(), 0u);
+    ensure_equals(empty_point_->getCoordinatesRO()->getSize(), 0u);
+}
+
 } // namespace tut
 

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

Summary of changes:
 include/geos/geom/FixedSizeCoordinateSequence.h    |  4 +--
 include/geos/geom/Point.h                          |  4 ++-
 src/geom/Point.cpp                                 | 35 +++++++++++++++-------
 .../unit/geom/FixedSizeCoordinateSequenceTest.cpp  | 16 ++++++++++
 tests/unit/geom/PointTest.cpp                      | 31 +++++++++++++++++++
 5 files changed, 77 insertions(+), 13 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list