Skip to content

Commit

Permalink
Merge pull request #4169 from rouault/intersects_comments
Browse files Browse the repository at this point in the history
Add code comments in GeographicBoundingBox::Private::intersects()/intersections()
  • Loading branch information
rouault authored Jun 10, 2024
2 parents 2ebf62c + ee91216 commit 5b68676
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/iso19111/metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,21 @@ bool GeographicBoundingBox::Private::intersects(const Private &other) const {
const double oN = other.north_;
const double oS = other.south_;

// Check intersection along the latitude axis
if (N < oS || S > oN) {
return false;
}

// Check world coverage of this bbox, and other bbox overlapping
// antimeridian (e.g. oW=175 and oE=-175)
// Check oW > oE written for symmetry with the intersection() method.
if (W == -180.0 && E == 180.0 && oW > oE) {
return true;
}

// Check world coverage of othre bbox, and this bbox overlapping
// antimeridian (e.g. W=175 and E=-175)
// Check W > E written for symmetry with the intersection() method.
if (oW == -180.0 && oE == 180.0 && W > E) {
return true;
}
Expand All @@ -353,7 +360,7 @@ bool GeographicBoundingBox::Private::intersects(const Private &other) const {
return intersects(Private(oW, oS, 180.0, oN)) ||
intersects(Private(-180.0, oS, oE, oN));

// No: crossing antimerian
// No: crossing antimeridian
} else {
if (oW <= oE) {
return other.intersects(*this);
Expand Down Expand Up @@ -402,15 +409,20 @@ GeographicBoundingBox::Private::intersection(const Private &otherExtent) const {
const double oN = otherExtent.north_;
const double oS = otherExtent.south_;

// Check intersection along the latitude axis
if (N < oS || S > oN) {
return nullptr;
}

// Check world coverage of this bbox, and other bbox overlapping
// antimeridian (e.g. oW=175 and oE=-175)
if (W == -180.0 && E == 180.0 && oW > oE) {
return internal::make_unique<Private>(oW, std::max(S, oS), oE,
std::min(N, oN));
}

// Check world coverage of othre bbox, and this bbox overlapping
// antimeridian (e.g. W=175 and E=-175)
if (oW == -180.0 && oE == 180.0 && W > E) {
return internal::make_unique<Private>(W, std::max(S, oS), E,
std::min(N, oN));
Expand Down Expand Up @@ -448,7 +460,7 @@ GeographicBoundingBox::Private::intersection(const Private &otherExtent) const {
return inter1;
}
return inter2;
// No: crossing antimerian
// No: crossing antimeridian
} else {
if (oW <= oE) {
return otherExtent.intersection(*this);
Expand Down

0 comments on commit 5b68676

Please sign in to comment.