Skip to content

Commit

Permalink
cheap equivalence tests in case of matching bounding box for polygons…
Browse files Browse the repository at this point in the history
… and lines
  • Loading branch information
patrickbr committed Sep 3, 2024
1 parent 9116309 commit a37821e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/spatialjoin/Sweeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,13 @@ sj::Area Sweeper::areaFromSimpleArea(const SimpleArea* sa) const {
std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const Area* a,
const Area* b,
size_t t) const {

// cheap equivalence check
if (a->box == b->box && a->area == b->area && a->geom == b->geom) {
// equivalent!
return {1, 0, 1, 0, 0};
}

if (_cfg.useBoxIds) {
auto ts = TIME();
auto r = boxIdIsect(a->boxIds, b->boxIds);
Expand Down Expand Up @@ -1367,6 +1374,12 @@ std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const Line* a,
std::tuple<bool, bool, bool, bool, bool> Sweeper::check(const Line* a,
const Line* b,
size_t t) const {
// cheap equivalence check
if (a->box == b->box && a->geom == b->geom) {
// equivalent!
return {1, 1, 0, 0, 0};
}

if (_cfg.useBoxIds) {
auto ts = TIME();
auto r = boxIdIsect(a->boxIds, b->boxIds);
Expand Down Expand Up @@ -2227,7 +2240,7 @@ void Sweeper::doCheck(const BoxVal cur, const SweepVal sv, size_t t) {

if (a->id == b->id)
return; // no self-checks in multigeometries
//

_stats[t].lineCmps++;
_stats[t].lineLenSum += std::max(a->length, b->length);

Expand Down
2 changes: 0 additions & 2 deletions src/spatialjoin/WKTParse.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ inline void parseLine(char* c, size_t len, size_t gid, sj::Sweeper* sweeper,
do {
*end = 0;
sweeper->add(c,

util::geo::I32Box({std::numeric_limits<int32_t>::min(),
std::numeric_limits<int32_t>::min()},
{std::numeric_limits<int32_t>::max(),
Expand All @@ -194,7 +193,6 @@ inline void parseLine(char* c, size_t len, size_t gid, sj::Sweeper* sweeper,

c[len - 2] = 0;
sweeper->add(c,

util::geo::I32Box({std::numeric_limits<int32_t>::min(),
std::numeric_limits<int32_t>::min()},
{std::numeric_limits<int32_t>::max(),
Expand Down
2 changes: 1 addition & 1 deletion src/util
Submodule util updated 2 files
+16 −2 geo/Line.h
+29 −0 geo/Polygon.h

0 comments on commit a37821e

Please sign in to comment.