[geos-commits] [SCM] GEOS branch main updated. bf2257aa3794b483fefe23497209a79d40492841
git at osgeo.org
git at osgeo.org
Tue Sep 24 13:56:48 PDT 2024
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 bf2257aa3794b483fefe23497209a79d40492841 (commit)
from 0d604cc650a5b6cfa2a32ff63d07a6908a67c9eb (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 bf2257aa3794b483fefe23497209a79d40492841
Author: Daniel Baston <dbaston at gmail.com>
Date: Tue Sep 24 16:56:29 2024 -0400
CompoundCurve: Add validateConstruction method (#1164)
Resolves https://github.com/libgeos/geos/issues/1103
diff --git a/include/geos/geom/CompoundCurve.h b/include/geos/geom/CompoundCurve.h
index 1dbdf0f23..211a4aaa4 100644
--- a/include/geos/geom/CompoundCurve.h
+++ b/include/geos/geom/CompoundCurve.h
@@ -86,6 +86,8 @@ public:
std::unique_ptr<CompoundCurve> reverse() const;
+ void validateConstruction() const;
+
protected:
/// Construct a CompoundCurve, taking ownership of the
/// provided CoordinateSequence
diff --git a/src/geom/CompoundCurve.cpp b/src/geom/CompoundCurve.cpp
index 2175c7ed2..740e7c5bc 100644
--- a/src/geom/CompoundCurve.cpp
+++ b/src/geom/CompoundCurve.cpp
@@ -12,6 +12,8 @@
*
**********************************************************************/
+#include <sstream>
+
#include <geos/geom/CompoundCurve.h>
#include <geos/geom/CoordinateFilter.h>
#include <geos/geom/GeometryFactory.h>
@@ -25,7 +27,9 @@ CompoundCurve::CompoundCurve(std::vector<std::unique_ptr<SimpleCurve>>&& p_curve
const GeometryFactory& gf)
: Curve(gf),
curves(std::move(p_curves)),
- envelope(computeEnvelopeInternal()) {}
+ envelope(computeEnvelopeInternal()) {
+ validateConstruction();
+}
CompoundCurve::CompoundCurve(const CompoundCurve& other)
: Curve(other),
@@ -307,5 +311,24 @@ CompoundCurve::reverseImpl() const
return getFactory()->createCompoundCurve(std::move(reversed)).release();
}
+void
+CompoundCurve::validateConstruction() const
+{
+ for (std::size_t i = 1; i < curves.size(); i++) {
+ const CoordinateXY& end = curves[i-1]->getCoordinatesRO()->back<CoordinateXY>();
+ const CoordinateXY& start = curves[i]->getCoordinatesRO()->front<CoordinateXY>();
+
+ if (start != end) {
+ std::ostringstream ss;
+
+ ss << "Sections of CompoundCurve are not contiguous: " <<
+ "curve " << (i-1) << " ends at " << end <<
+ " ; curve " << i << " begins at " << start;
+
+ throw util::IllegalArgumentException(ss.str());
+ }
+ }
+}
+
}
}
diff --git a/tests/unit/geom/CompoundCurveTest.cpp b/tests/unit/geom/CompoundCurveTest.cpp
index a430842fa..958cf109e 100644
--- a/tests/unit/geom/CompoundCurveTest.cpp
+++ b/tests/unit/geom/CompoundCurveTest.cpp
@@ -11,8 +11,10 @@
#include <geos/io/WKTReader.h>
#include <geos/util.h>
+using geos::geom::CompoundCurve;
using geos::geom::CoordinateXY;
using geos::geom::CoordinateSequence;
+using geos::geom::SimpleCurve;
namespace tut {
// Common data used by tests
@@ -21,11 +23,11 @@ struct test_compoundcurve_data {
geos::geom::GeometryFactory::Ptr factory_ = geos::geom::GeometryFactory::create();
geos::io::WKTReader wktreader_;
- std::unique_ptr<geos::geom::CompoundCurve> cc_;
+ std::unique_ptr<CompoundCurve> cc_;
test_compoundcurve_data()
{
- std::vector<std::unique_ptr<geos::geom::SimpleCurve>> curves;
+ std::vector<std::unique_ptr<SimpleCurve>> curves;
curves.emplace_back(factory_->createCircularString({
CoordinateXY(0, 0),
@@ -312,6 +314,17 @@ void object::test<8>()
ensure_equals(tcsf.args[3].second, 0u);
}
+template<>
+template<>
+void object::test<9>()
+{
+ std::vector<std::unique_ptr<SimpleCurve>> curves;
+
+ curves.push_back(wktreader_.read<SimpleCurve>("LINESTRING (0 0, 1 2)"));
+ curves.push_back(wktreader_.read<SimpleCurve>("CIRCULARSTRING (2 1, 3 3, 4 1)"));
+
+ ensure_THROW(factory_->createCompoundCurve(std::move(curves)), geos::util::IllegalArgumentException);
+}
}
diff --git a/tests/unit/io/WKTWriterTest.cpp b/tests/unit/io/WKTWriterTest.cpp
index 8618f8be0..4622e9b98 100644
--- a/tests/unit/io/WKTWriterTest.cpp
+++ b/tests/unit/io/WKTWriterTest.cpp
@@ -763,9 +763,9 @@ void object::test<22>()
geom = wktreader.read("CIRCULARSTRING (0 0, 1 1, 2 0)");
ensure_equals(wktwriter.writeFormatted(geom.get()), "CIRCULARSTRING (0 0, 1 1, 2 0)");
- geom = wktreader.read("COMPOUNDCURVE((0 10, 0 5), CIRCULARSTRING (0 0, 1 1, 2 0), (2 0, 3 0))");
+ geom = wktreader.read("COMPOUNDCURVE((0 10, 0 5), CIRCULARSTRING (0 5, 1 1, 2 0), (2 0, 3 0))");
ensure_equals(wktwriter.writeFormatted(geom.get()), "COMPOUNDCURVE ((0 10, 0 5), \n"
- " CIRCULARSTRING (0 0, 1 1, 2 0), \n"
+ " CIRCULARSTRING (0 5, 1 1, 2 0), \n"
" (2 0, 3 0))");
geom = wktreader.read("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (1 1, 1 2, 2 2, 2 1, 1 1), (3 3, 3 4, 4 4, 4 3, 3 3))");
@@ -786,9 +786,9 @@ void object::test<22>()
" (2 2, 3 3), \n"
" (4 4, 5 5))");
- geom = wktreader.read("MULTICURVE ((0 0, 1 1), COMPOUNDCURVE ((2 2, 3 3), CIRCULARSTRING (4 4, 5 5, 6 4), (6 4, 7 4)), (100 100, 200 200))");
+ geom = wktreader.read("MULTICURVE ((0 0, 1 1), COMPOUNDCURVE ((2 2, 4 4), CIRCULARSTRING (4 4, 5 5, 6 4), (6 4, 7 4)), (100 100, 200 200))");
ensure_equals(wktwriter.writeFormatted(geom.get()), "MULTICURVE ((0 0, 1 1), \n"
- " COMPOUNDCURVE ((2 2, 3 3), \n"
+ " COMPOUNDCURVE ((2 2, 4 4), \n"
" CIRCULARSTRING (4 4, 5 5, 6 4), \n"
" (6 4, 7 4)), \n"
" (100 100, 200 200))");
-----------------------------------------------------------------------
Summary of changes:
include/geos/geom/CompoundCurve.h | 2 ++
src/geom/CompoundCurve.cpp | 25 ++++++++++++++++++++++++-
tests/unit/geom/CompoundCurveTest.cpp | 17 +++++++++++++++--
tests/unit/io/WKTWriterTest.cpp | 8 ++++----
4 files changed, 45 insertions(+), 7 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list