[geos-commits] [SCM] GEOS branch main-relate-ng updated. bc3e7cea24aaa6794863d740455f7901948cb280
git at osgeo.org
git at osgeo.org
Mon Aug 12 16:04:19 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-relate-ng has been updated
via bc3e7cea24aaa6794863d740455f7901948cb280 (commit)
from ce259945da21066105ad19fa2a9f986df5b2ef6a (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 bc3e7cea24aaa6794863d740455f7901948cb280
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Mon Aug 12 16:03:45 2024 -0700
Fix lifecycle issues in mem management
diff --git a/include/geos/geom/prep/BasicPreparedGeometry.h b/include/geos/geom/prep/BasicPreparedGeometry.h
index a666564b8..068ade2bc 100644
--- a/include/geos/geom/prep/BasicPreparedGeometry.h
+++ b/include/geos/geom/prep/BasicPreparedGeometry.h
@@ -128,6 +128,11 @@ public:
*/
bool isAnyTargetComponentInTest(const geom::Geometry* testGeom) const;
+ /**
+ * Default implementation.
+ */
+ bool within(const geom::Geometry* g) const override;
+
/**
* Default implementation.
*/
@@ -174,11 +179,6 @@ public:
*/
bool touches(const geom::Geometry* g) const override;
- /**
- * Default implementation.
- */
- bool within(const geom::Geometry* g) const override;
-
/**
* Default implementation.
*/
diff --git a/include/geos/operation/relateng/RelateGeometry.h b/include/geos/operation/relateng/RelateGeometry.h
index 81260efbb..3c071d056 100644
--- a/include/geos/operation/relateng/RelateGeometry.h
+++ b/include/geos/operation/relateng/RelateGeometry.h
@@ -77,7 +77,8 @@ private:
/*
* Memory contexts for lower level allocations
*/
- std::vector<std::unique_ptr<const RelateSegmentString>> segStringStore;
+ std::vector<std::unique_ptr<const RelateSegmentString>> segStringTempStore;
+ std::vector<std::unique_ptr<const RelateSegmentString>> segStringPermStore;
std::vector<std::unique_ptr<CoordinateSequence>> csStore;
@@ -103,16 +104,19 @@ private:
void extractSegmentStringsFromAtomic(bool isA,
const Geometry* geom, const MultiPolygon* parentPolygonal,
const Envelope* env,
- std::vector<const SegmentString*>& segStrings);
+ std::vector<const SegmentString*>& segStrings,
+ std::vector<std::unique_ptr<const RelateSegmentString>>& segStore);
void extractRingToSegmentString(bool isA,
const LinearRing* ring, int ringId, const Envelope* env,
const Geometry* parentPoly,
- std::vector<const SegmentString*>& segStrings);
+ std::vector<const SegmentString*>& segStrings,
+ std::vector<std::unique_ptr<const RelateSegmentString>>& segStore);
void extractSegmentStrings(bool isA,
const Envelope* env, const Geometry* geom,
- std::vector<const SegmentString*>& segStrings);
+ std::vector<const SegmentString*>& segStrings,
+ std::vector<std::unique_ptr<const RelateSegmentString>>& segStore);
const CoordinateSequence* orientAndRemoveRepeated(
const CoordinateSequence* cs, bool orientCW);
diff --git a/src/geom/prep/BasicPreparedGeometry.cpp b/src/geom/prep/BasicPreparedGeometry.cpp
index 4d2816fe4..c346fcf42 100644
--- a/src/geom/prep/BasicPreparedGeometry.cpp
+++ b/src/geom/prep/BasicPreparedGeometry.cpp
@@ -90,6 +90,12 @@ BasicPreparedGeometry::isAnyTargetComponentInTest(const geom::Geometry* testGeom
return false;
}
+bool
+BasicPreparedGeometry::within(const geom::Geometry* g) const
+{
+ return getRelateNG()->within(g);
+}
+
bool
BasicPreparedGeometry::contains(const geom::Geometry* g) const
{
@@ -144,12 +150,6 @@ BasicPreparedGeometry::touches(const geom::Geometry* g) const
return getRelateNG()->touches(g);
}
-bool
-BasicPreparedGeometry::within(const geom::Geometry* g) const
-{
- return getRelateNG()->within(g);
-}
-
bool
BasicPreparedGeometry::relate(const geom::Geometry* g, const std::string& pat) const
{
diff --git a/src/operation/relateng/RelateGeometry.cpp b/src/operation/relateng/RelateGeometry.cpp
index 6c5cb6c78..b3bbfa6b8 100644
--- a/src/operation/relateng/RelateGeometry.cpp
+++ b/src/operation/relateng/RelateGeometry.cpp
@@ -364,8 +364,21 @@ std::vector<const SegmentString*>
RelateGeometry::extractSegmentStrings(bool isA, const Envelope* env)
{
std::vector<const SegmentString*> segStrings;
- segStringStore.clear();
- extractSegmentStrings(isA, env, geom, segStrings);
+
+ if (isA && isPrepared() && env == nullptr) {
+ if (segStringPermStore.empty()) {
+ extractSegmentStrings(isA, env, geom, segStrings, segStringPermStore);
+ }
+ else {
+ for (auto& ss : segStringPermStore) {
+ segStrings.push_back(ss.get());
+ }
+ }
+ }
+ else {
+ segStringTempStore.clear();
+ extractSegmentStrings(isA, env, geom, segStrings, segStringTempStore);
+ }
return segStrings;
}
@@ -374,7 +387,8 @@ RelateGeometry::extractSegmentStrings(bool isA, const Envelope* env)
void
RelateGeometry::extractSegmentStrings(bool isA,
const Envelope* env, const Geometry* p_geom,
- std::vector<const SegmentString*>& segStrings)
+ std::vector<const SegmentString*>& segStrings,
+ std::vector<std::unique_ptr<const RelateSegmentString>>& segStore)
{
//-- record if parent is MultiPolygon
const MultiPolygon* parentPolygonal = nullptr;
@@ -386,10 +400,10 @@ RelateGeometry::extractSegmentStrings(bool isA,
const Geometry* g = p_geom->getGeometryN(i);
// if (g->getGeometryTypeId() == GEOS_GEOMETRYCOLLECTION) {
if (g->isCollection()) {
- extractSegmentStrings(isA, env, g, segStrings);
+ extractSegmentStrings(isA, env, g, segStrings, segStore);
}
else {
- extractSegmentStringsFromAtomic(isA, g, parentPolygonal, env, segStrings);
+ extractSegmentStringsFromAtomic(isA, g, parentPolygonal, env, segStrings, segStore);
}
}
}
@@ -400,7 +414,8 @@ void
RelateGeometry::extractSegmentStringsFromAtomic(bool isA,
const Geometry* p_geom, const MultiPolygon* parentPolygonal,
const Envelope* env,
- std::vector<const SegmentString*>& segStrings)
+ std::vector<const SegmentString*>& segStrings,
+ std::vector<std::unique_ptr<const RelateSegmentString>>& segStore)
{
if (p_geom->isEmpty())
return;
@@ -419,7 +434,7 @@ RelateGeometry::extractSegmentStringsFromAtomic(bool isA,
*/
const CoordinateSequence* cs = removeRepeated(line->getCoordinatesRO());
auto ss = RelateSegmentString::createLine(cs, isA, elementId, this);
- segStringStore.emplace_back(ss);
+ segStore.emplace_back(ss);
segStrings.push_back(ss);
}
else if (p_geom->getGeometryTypeId() == GEOS_POLYGON) {
@@ -429,9 +444,9 @@ RelateGeometry::extractSegmentStringsFromAtomic(bool isA,
parentPoly = static_cast<const Geometry*>(parentPolygonal);
else
parentPoly = static_cast<const Geometry*>(poly);
- extractRingToSegmentString(isA, poly->getExteriorRing(), 0, env, parentPoly, segStrings);
+ extractRingToSegmentString(isA, poly->getExteriorRing(), 0, env, parentPoly, segStrings, segStore);
for (uint32_t i = 0; i < poly->getNumInteriorRing(); i++) {
- extractRingToSegmentString(isA, poly->getInteriorRingN(i), static_cast<int>(i+1), env, parentPoly, segStrings);
+ extractRingToSegmentString(isA, poly->getInteriorRingN(i), static_cast<int>(i+1), env, parentPoly, segStrings, segStore);
}
}
}
@@ -442,7 +457,8 @@ void
RelateGeometry::extractRingToSegmentString(bool isA,
const LinearRing* ring, int ringId, const Envelope* env,
const Geometry* parentPoly,
- std::vector<const SegmentString*>& segStrings)
+ std::vector<const SegmentString*>& segStrings,
+ std::vector<std::unique_ptr<const RelateSegmentString>>& segStore)
{
if (ring->isEmpty())
return;
@@ -457,7 +473,7 @@ RelateGeometry::extractRingToSegmentString(bool isA,
bool requireCW = (ringId == 0);
const CoordinateSequence* cs = orientAndRemoveRepeated(ring->getCoordinatesRO(), requireCW);
auto ss = RelateSegmentString::createRing(cs, isA, elementId, ringId, parentPoly, this);
- segStringStore.emplace_back(ss);
+ segStore.emplace_back(ss);
segStrings.push_back(ss);
}
diff --git a/src/operation/relateng/RelateNG.cpp b/src/operation/relateng/RelateNG.cpp
index 42a965ba5..283f6ff19 100644
--- a/src/operation/relateng/RelateNG.cpp
+++ b/src/operation/relateng/RelateNG.cpp
@@ -674,10 +674,10 @@ RelateNG::computeEdgesMutual(std::vector<const SegmentString*>& edgesB, const En
std::vector<const SegmentString*> edgesA = geomA.extractSegmentStrings(GEOM_A, envExtract);
edgeMutualInt.reset(new MCIndexSegmentSetMutualIntersector(envExtract));
edgeMutualInt->setBaseSegments(&edgesA);
- edgeMutualInt->setSegmentIntersector(&intersector);
}
+ edgeMutualInt->setSegmentIntersector(&intersector);
edgeMutualInt->process(&edgesB);
}
diff --git a/tests/unit/operation/relateng/RelateNGTest.cpp b/tests/unit/operation/relateng/RelateNGTest.cpp
index 44196301e..7e54c71c9 100644
--- a/tests/unit/operation/relateng/RelateNGTest.cpp
+++ b/tests/unit/operation/relateng/RelateNGTest.cpp
@@ -466,8 +466,6 @@ void object::test<32> ()
std::string a = "POLYGON ((1 5, 5 5, 5 1, 1 1, 1 5))";
std::string b = "LINESTRING (2 3, 3 5, 4 3)";
checkIntersectsDisjoint(a, b, true);
- //checkContainsWithin(a, b, true);
- //checkCoversCoveredBy(a, b, true);
checkTouches(a, b, false);
checkOverlaps(a, b, false);
}
diff --git a/tests/unit/operation/relateng/RelateNGTest.h b/tests/unit/operation/relateng/RelateNGTest.h
index a33ef1853..70526d6de 100644
--- a/tests/unit/operation/relateng/RelateNGTest.h
+++ b/tests/unit/operation/relateng/RelateNGTest.h
@@ -27,6 +27,13 @@ struct test_relateng_support {
WKTReader r;
WKTWriter w;
+ void checkPrepared(const std::string& wkta, const std::string& wktb)
+ {
+ std::unique_ptr<Geometry> a = r.read(wkta);
+ std::unique_ptr<Geometry> b = r.read(wktb);
+ return checkPrepared(a.get(), b.get());
+ }
+
void checkPrepared(const Geometry* a, const Geometry* b)
{
auto prep_a = RelateNG::prepare(a);
@@ -40,7 +47,7 @@ struct test_relateng_support {
ensure_equals("preparedContains", prep_a->contains(b), a->contains(b));
ensure_equals("preparedCrosses", prep_a->crosses(b), a->crosses(b));
ensure_equals("preparedTouches", prep_a->touches(b), a->touches(b));
- ensure_equals("preparedRelate", prep_a->relate(b)->toString(), a->relate(b)->toString());
+ ensure_equals("preparedRelate", prep_a->relate(b)->toString(), a->relate(b)->toString());
}
void checkIntersectsDisjoint(const std::string& wkta, const std::string& wktb, bool expectedValue)
-----------------------------------------------------------------------
Summary of changes:
include/geos/geom/prep/BasicPreparedGeometry.h | 10 +++----
include/geos/operation/relateng/RelateGeometry.h | 12 +++++---
src/geom/prep/BasicPreparedGeometry.cpp | 12 ++++----
src/operation/relateng/RelateGeometry.cpp | 38 +++++++++++++++++-------
src/operation/relateng/RelateNG.cpp | 2 +-
tests/unit/operation/relateng/RelateNGTest.cpp | 2 --
tests/unit/operation/relateng/RelateNGTest.h | 9 +++++-
7 files changed, 55 insertions(+), 30 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list