Skip to content

Commit

Permalink
Merge branch 'main' into main-perf-ng
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Aug 15, 2024
2 parents cc9c0e3 + e8e3e25 commit 6b1e19e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 52 deletions.
22 changes: 10 additions & 12 deletions capi/geos_ts_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
#include <geos/operation/valid/RepeatedPointRemover.h>

#include <geos/operation/relateng/RelateNG.h>
#include <geos/operation/relateng/RelatePredicate.h>

#include <geos/precision/GeometryPrecisionReducer.h>
#include <geos/shape/fractal/HilbertEncoder.h>
Expand Down Expand Up @@ -210,7 +209,6 @@ using geos::operation::overlayng::OverlayNG;
using geos::operation::overlayng::UnaryUnionNG;
using geos::operation::overlayng::OverlayNGRobust;
using geos::operation::relateng::RelateNG;
using geos::operation::relateng::RelatePredicate;
using geos::operation::valid::TopologyValidationError;

using geos::precision::GeometryPrecisionReducer;
Expand Down Expand Up @@ -583,79 +581,79 @@ extern "C" {
GEOSDisjoint_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2)
{
return execute(extHandle, 2, [&]() {
return RelateNG::disjoint(g1, g2);
return g1->disjoint(g2);
});
}

char
GEOSTouches_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2)
{
return execute(extHandle, 2, [&]() {
return RelateNG::touches(g1, g2);
return g1->touches(g2);
});
}

char
GEOSIntersects_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2)
{
return execute(extHandle, 2, [&]() {
return RelateNG::intersects(g1, g2);
return g1->intersects(g2);
});
}

char
GEOSCrosses_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2)
{
return execute(extHandle, 2, [&]() {
return RelateNG::crosses(g1, g2);
return g1->crosses(g2);
});
}

char
GEOSWithin_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2)
{
return execute(extHandle, 2, [&]() {
return RelateNG::within(g1, g2);
return g1->within(g2);
});
}

char
GEOSContains_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2)
{
return execute(extHandle, 2, [&]() {
return RelateNG::contains(g1, g2);
return g1->contains(g2);
});
}

char
GEOSOverlaps_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2)
{
return execute(extHandle, 2, [&]() {
return RelateNG::overlaps(g1, g2);
return g1->overlaps(g2);
});
}

char
GEOSCovers_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2)
{
return execute(extHandle, 2, [&]() {
return RelateNG::covers(g1, g2);
return g1->covers(g2);
});
}

char
GEOSCoveredBy_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2)
{
return execute(extHandle, 2, [&]() {
return RelateNG::coveredBy(g1, g2);
return g1->coveredBy(g2);
});
}

char
GEOSEquals_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2)
{
return execute(extHandle, 2, [&]() {
return RelateNG::equalsTopo(g1, g2);
return g1->equals(g2);
});
}

Expand Down
4 changes: 2 additions & 2 deletions include/geos/geom/prep/BasicPreparedGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ class BasicPreparedGeometry: public PreparedGeometry {
std::vector<const CoordinateXY*> representativePts;
mutable std::unique_ptr<RelateNG> relate_ng;

std::unique_ptr<RelateNG>& getRelateNG() const
RelateNG& getRelateNG() const
{
if (relate_ng == nullptr)
relate_ng = RelateNG::prepare(baseGeom);

return relate_ng;
return *relate_ng;
}

protected:
Expand Down
6 changes: 0 additions & 6 deletions include/geos/index/chain/MonotoneChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ class GEOS_DLL MonotoneChain {
return context;
}

void setId(int p_id) { id = p_id; }
int getId() const { return id; }

private:

void computeSelect(const geom::Envelope& searchEnv,
Expand Down Expand Up @@ -201,9 +198,6 @@ class GEOS_DLL MonotoneChain {
/// Owned by this class
mutable geom::Envelope env;

/// Useful for optimizing chain comparisons
int id = 0;

};

} // namespace geos::index::chain
Expand Down
3 changes: 1 addition & 2 deletions include/geos/operation/relateng/EdgeSetIntersector.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GEOS_DLL EdgeSetIntersector {
// HPRtree index = new HPRtree();
const Envelope* envelope = nullptr;
std::deque<MonotoneChain> monoChains;
int idCounter = 0;
std::size_t overlapCounter = 0;


// Methods
Expand All @@ -76,7 +76,6 @@ class GEOS_DLL EdgeSetIntersector {
std::vector<const SegmentString*>& edgesB,
const Envelope* env)
: envelope(env)
, idCounter(0)
{
addEdges(edgesA);
addEdges(edgesB);
Expand Down
24 changes: 12 additions & 12 deletions src/geom/prep/BasicPreparedGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,73 +93,73 @@ BasicPreparedGeometry::isAnyTargetComponentInTest(const geom::Geometry* testGeom
bool
BasicPreparedGeometry::within(const geom::Geometry* g) const
{
return getRelateNG()->within(g);
return getRelateNG().within(g);
}

bool
BasicPreparedGeometry::contains(const geom::Geometry* g) const
{
return getRelateNG()->contains(g);
return getRelateNG().contains(g);
}

bool
BasicPreparedGeometry::containsProperly(const geom::Geometry* g) const
{
return getRelateNG()->relate(g, "T**FF*FF*");
return getRelateNG().relate(g, "T**FF*FF*");
}

bool
BasicPreparedGeometry::coveredBy(const geom::Geometry* g) const
{
return getRelateNG()->coveredBy(g);
return getRelateNG().coveredBy(g);
}

bool
BasicPreparedGeometry::covers(const geom::Geometry* g) const
{
return getRelateNG()->covers(g);
return getRelateNG().covers(g);
}

bool
BasicPreparedGeometry::crosses(const geom::Geometry* g) const
{
return getRelateNG()->crosses(g);
return getRelateNG().crosses(g);
}

bool
BasicPreparedGeometry::disjoint(const geom::Geometry* g) const
{
return getRelateNG()->disjoint(g);
return getRelateNG().disjoint(g);
}

bool
BasicPreparedGeometry::intersects(const geom::Geometry* g) const
{
return getRelateNG()->intersects(g);
return getRelateNG().intersects(g);
}

bool
BasicPreparedGeometry::overlaps(const geom::Geometry* g) const
{
return getRelateNG()->overlaps(g);
return getRelateNG().overlaps(g);
}

bool
BasicPreparedGeometry::touches(const geom::Geometry* g) const
{
return getRelateNG()->touches(g);
return getRelateNG().touches(g);
}

bool
BasicPreparedGeometry::relate(const geom::Geometry* g, const std::string& pat) const
{
return getRelateNG()->relate(g, pat);
return getRelateNG().relate(g, pat);
}

std::unique_ptr<IntersectionMatrix>
BasicPreparedGeometry::relate(const geom::Geometry* g) const
{
return getRelateNG()->relate(g);
return getRelateNG().relate(g);
}


Expand Down
29 changes: 11 additions & 18 deletions src/operation/relateng/EdgeSetIntersector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <geos/operation/relateng/RelateSegmentString.h>
#include <geos/index/chain/MonotoneChain.h>
#include <geos/index/chain/MonotoneChainBuilder.h>
#include <geos/util/Interrupt.h>


using geos::geom::Geometry;
Expand Down Expand Up @@ -54,7 +55,7 @@ EdgeSetIntersector::addToIndex(const SegmentString* segStr)

for (MonotoneChain& mc : segChains) {
if (envelope == nullptr || envelope->intersects(mc.getEnvelope())) {
mc.setId(idCounter++);
// mc.setId(idCounter++);
monoChains.push_back(mc);
MonotoneChain* mcPtr = &(monoChains.back());
index.insert(mcPtr->getEnvelope(), mcPtr);
Expand All @@ -68,26 +69,18 @@ EdgeSetIntersector::process(EdgeSegmentIntersector& intersector)
{
EdgeSegmentOverlapAction overlapAction(intersector);

for (const MonotoneChain& queryChain : monoChains) {
// Replaces JTS implementation that manually iterates on the
// monoChains with the automatic queryPairs method in TemplateSTRTree
index.queryPairs([this, &overlapAction, &intersector](const MonotoneChain* queryChain, const MonotoneChain* testChain) {

std::vector<const MonotoneChain*> overlapChains;
index.query(queryChain.getEnvelope(), [&overlapChains](const MonotoneChain* mc) {
overlapChains.push_back(mc);
});
if (overlapCounter++ % 100000 == 0)
GEOS_CHECK_FOR_INTERRUPTS();

for (const MonotoneChain* testChain : overlapChains) {
/**
* following test makes sure we only compare each pair of chains once
* and that we don't compare a chain to itself
*/
if (testChain->getId() <= queryChain.getId())
continue;
testChain->computeOverlaps(queryChain, &overlapAction);

return !intersector.isDone();
});

testChain->computeOverlaps(&queryChain, &overlapAction);
if (intersector.isDone())
return;
}
}
}


Expand Down

0 comments on commit 6b1e19e

Please sign in to comment.