[geos-commits] [SCM] GEOS branch master updated. 5ce4076b7e67f8f978ad34f0127728957edc1c3a

git at osgeo.org git at osgeo.org
Mon Dec 17 12:14:38 PST 2018


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  5ce4076b7e67f8f978ad34f0127728957edc1c3a (commit)
      from  c821855f5cb1841e027b22aa8d8f733f37412165 (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 5ce4076b7e67f8f978ad34f0127728957edc1c3a
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date:   Mon Dec 17 12:14:19 2018 -0800

    Move length functions to Length class
    JTS 1b7bb75fcdeb1cbde1fe6c6deb2cde18929868d7

diff --git a/include/geos/algorithm/Length.h b/include/geos/algorithm/Length.h
new file mode 100644
index 0000000..4af0b77
--- /dev/null
+++ b/include/geos/algorithm/Length.h
@@ -0,0 +1,53 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2018 Paul Ramsey <pramsey at cleverlephant.ca>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************
+ *
+ * Last port: algorithm/Length.java @ 2017-09-04
+ *
+ **********************************************************************/
+
+#ifndef GEOS_ALGORITHM_LENGTH_H
+#define GEOS_ALGORITHM_LENGTH_H
+
+#include <geos/export.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
+
+namespace geos {
+namespace algorithm { // geos::algorithm
+
+/**
+* Functions for computing length.
+*
+* @author Martin Davis
+*
+*/
+class GEOS_DLL Length {
+public:
+
+    /**
+    * Computes the length of a linestring specified by a sequence of points.
+    *
+    * @param pts the points specifying the linestring
+    * @return the length of the linestring
+    */
+    static double ofLine(const geom::CoordinateSequence *ring);
+
+};
+
+
+} // namespace geos::algorithm
+} // namespace geos
+
+
+#endif // GEOS_ALGORITHM_LENGTH_H
diff --git a/include/geos/algorithm/Makefile.am b/include/geos/algorithm/Makefile.am
index 0c9d319..2791033 100644
--- a/include/geos/algorithm/Makefile.am
+++ b/include/geos/algorithm/Makefile.am
@@ -24,6 +24,7 @@ geos_HEADERS = \
 	InteriorPointLine.h \
 	InteriorPointPoint.h \
 	LineIntersector.h \
+	Length.h \
 	MinimumDiameter.h \
 	NotRepresentableException.h \
 	PointLocator.h \
diff --git a/src/algorithm/Length.cpp b/src/algorithm/Length.cpp
new file mode 100644
index 0000000..dfb71cb
--- /dev/null
+++ b/src/algorithm/Length.cpp
@@ -0,0 +1,61 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2018 Paul Ramsey <pramsey at cleverlephant.ca>
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ **********************************************************************
+ *
+ * Last port: algorithm/Length.java @ 2017-09-04
+ *
+ **********************************************************************/
+
+#include <cmath>
+#include <vector>
+
+#include <geos/algorithm/Length.h>
+
+namespace geos {
+namespace algorithm { // geos.algorithm
+
+/* public static */
+double
+Length::ofLine(const geom::CoordinateSequence *pts)
+{
+    // optimized for processing CoordinateSequences
+    size_t n = pts->size();
+    if (n <= 1)
+        return 0.0;
+
+    double len = 0.0;
+
+    geom::Coordinate p;
+    p = pts->getAt(0);
+    double x0 = p.x;
+    double y0 = p.y;
+
+    for (size_t i = 1; i < n; i++) {
+        p = pts->getAt(i);
+        double x1 = p.x;
+        double y1 = p.y;
+        double dx = x1 - x0;
+        double dy = y1 - y0;
+
+        len += std::sqrt(dx * dx + dy * dy);
+
+        x0 = x1;
+        y0 = y1;
+    }
+    return len;
+}
+
+
+} // namespace geos.algorithm
+} //namespace geos
+
diff --git a/src/algorithm/Makefile.am b/src/algorithm/Makefile.am
index 7f84e78..d316f85 100644
--- a/src/algorithm/Makefile.am
+++ b/src/algorithm/Makefile.am
@@ -22,6 +22,7 @@ libalgorithm_la_SOURCES = \
 	InteriorPointLine.cpp \
 	InteriorPointPoint.cpp \
 	LineIntersector.cpp \
+	Length.cpp \
 	MinimumDiameter.cpp \
 	NotRepresentableException.cpp \
 	PointLocator.cpp \
diff --git a/src/geom/LineString.cpp b/src/geom/LineString.cpp
index 14bc1c1..30bcab8 100644
--- a/src/geom/LineString.cpp
+++ b/src/geom/LineString.cpp
@@ -19,7 +19,7 @@
  **********************************************************************/
 
 #include <geos/util/IllegalArgumentException.h>
-#include <geos/algorithm/CGAlgorithms.h>
+#include <geos/algorithm/Length.h>
 #include <geos/geom/Coordinate.h>
 #include <geos/geom/CoordinateSequenceFactory.h>
 #include <geos/geom/CoordinateSequence.h>
@@ -375,7 +375,7 @@ LineString::getCoordinate() const
 double
 LineString::getLength() const
 {
-	return CGAlgorithms::length(points.get());
+	return Length::ofLine(points.get());
 }
 
 void
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index 9064b1f..2dcbd1c 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -49,6 +49,7 @@ geos_unit_SOURCES = \
 	algorithm/distance/DiscreteFrechetDistanceTest.cpp \
 	algorithm/distance/DiscreteHausdorffDistanceTest.cpp \
 	algorithm/InteriorPointAreaTest.cpp \
+	algorithm/LengthTest.cpp \
 	algorithm/LocatePointInRingTest.cpp \
 	algorithm/MinimumDiameterTest.cpp \
 	algorithm/OrientationIndexFailureTest.cpp \
diff --git a/tests/unit/algorithm/AreaTest.cpp b/tests/unit/algorithm/AreaTest.cpp
index 0c4b209..bc8cc65 100644
--- a/tests/unit/algorithm/AreaTest.cpp
+++ b/tests/unit/algorithm/AreaTest.cpp
@@ -80,23 +80,6 @@ namespace tut
         }
     };
 
-        // using geos::geom::LineString;
-
-        // Geometry::Ptr lineGeom(reader_.read("LINESTRING (30 220, 240 220, 240 220)"));
-        // LineString::Ptr line(dynamic_cast<LineString*>(lineGeom.release()));
-        // ensure(nullptr != line.get());
-
-        // Geometry::Ptr hullGeom(reader_.read("LINESTRING (30 220, 240 220)"));
-        // LineString::Ptr convexHull(dynamic_cast<LineString*>(hullGeom.release()));
-        // ensure(nullptr != convexHull.get());
-
-        // geom_ = line->convexHull();
-        // ensure( convexHull->equalsExact(geom_) );
-
-
-
-
-
     typedef test_group<test_area_data> group;
     typedef group::object object;
 
diff --git a/tests/unit/algorithm/LengthTest.cpp b/tests/unit/algorithm/LengthTest.cpp
new file mode 100644
index 0000000..8b277f7
--- /dev/null
+++ b/tests/unit/algorithm/LengthTest.cpp
@@ -0,0 +1,91 @@
+//
+// Test Suite for geos::algorithm::Length
+// Ported from JTS junit/algorithm/LengthTest.java
+
+#include <tut/tut.hpp>
+// geos
+#include <geos/algorithm/Length.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateArraySequence.h>
+#include <geos/geom/Dimension.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/geom/LineString.h>
+#include <geos/geom/PrecisionModel.h>
+#include <geos/io/WKTReader.h>
+// std
+#include <sstream>
+#include <string>
+#include <memory>
+
+using namespace geos;
+using namespace geos::geom;
+
+namespace tut
+{
+	//
+	// Test Group
+	//
+
+	// dummy data, not used
+	struct test_length_data {
+        geos::geom::Geometry *geom_;
+        geos::geom::PrecisionModel pm_;
+        geos::geom::GeometryFactory::Ptr factory_;
+        geos::io::WKTReader reader_;
+        test_length_data():
+            geom_(nullptr),
+            pm_(1),
+            factory_(GeometryFactory::create(&pm_, 0)), reader_(factory_.get())
+        {
+            assert(nullptr == geom_);
+        }
+
+        ~test_length_data()
+        {
+            factory_->destroyGeometry(geom_);
+            geom_ = nullptr;
+        }
+
+        void checkLengthOfLine(std::string wkt, double expectedLength) {
+            std::unique_ptr<Geometry> lineGeom(reader_.read(wkt));
+            std::unique_ptr<LineString> line(dynamic_cast<LineString*>(lineGeom.release()));
+            ensure(nullptr != line.get());
+            const CoordinateSequence *lineSeq = line->getCoordinatesRO();
+            double actual = algorithm::Length::ofLine(lineSeq);
+            ensure_equals(actual, expectedLength);
+        }
+
+    };
+
+ // void checkLengthOfLine(String wkt, double expectedLen) {
+ //    LineString ring = (LineString) read(wkt);
+
+ //    CoordinateSequence pts = ring.getCoordinateSequence();
+ //    double actual = Length.ofLine(pts);
+ //    assertEquals(actual, expectedLen);
+ //  }
+
+
+
+
+    typedef test_group<test_length_data> group;
+    typedef group::object object;
+
+    group test_length_group("geos::algorithm::Length");
+
+
+    //
+    // Test Cases
+    //
+    template<>
+    template<>
+    void object::test<1>()
+    {
+        checkLengthOfLine("LINESTRING (100 200, 200 200, 200 100, 100 100, 100 200)", 400.0);
+    }
+
+
+
+} // namespace tut
+

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

Summary of changes:
 include/geos/algorithm/Length.h     | 53 +++++++++++++++++++++
 include/geos/algorithm/Makefile.am  |  1 +
 src/algorithm/Length.cpp            | 61 +++++++++++++++++++++++++
 src/algorithm/Makefile.am           |  1 +
 src/geom/LineString.cpp             |  4 +-
 tests/unit/Makefile.am              |  1 +
 tests/unit/algorithm/AreaTest.cpp   | 17 -------
 tests/unit/algorithm/LengthTest.cpp | 91 +++++++++++++++++++++++++++++++++++++
 8 files changed, 210 insertions(+), 19 deletions(-)
 create mode 100644 include/geos/algorithm/Length.h
 create mode 100644 src/algorithm/Length.cpp
 create mode 100644 tests/unit/algorithm/LengthTest.cpp


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list