boostorg / boostorg/geometry

Inconsistency in overlaps() vs. intersection()?

Open
#704 5 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
517
Forks
232
PR merge metrics
No merged PRs in 30d

Description

Hi,

I'm confused about a particular case of checking for overlaps. I've got two polygons, `p1` and `p2`, that meet along a line. I'm expecting `overlaps(p1,p2)` to return `false`, but I get back `true`. What's weird about that is that when I try to prise apart what's happening, I find that the intersection of `p1` and `p2` is empty, which is inconsistent with the claim that the shapes overlap. Am I doing something obviously wrong, or am I misunderstanding the behaviour of `overlaps()`, or is it simple floating point imprecision and I'm out of luck?

Full code appended below. Thanks for the help!

```
#include
#include

#include

typedef boost::geometry::model::d2::point_xy point;
typedef boost::geometry::model::polygon polygon;

int main( void )
{
polygon p1;
polygon p2;

boost::geometry::read_wkt( "POLYGON((0.6666666666685 -1.5396007178376,1.6666
666666685 -1.5396007178376,1.16666666667 -0.673575314055,0.166666666667 1.058475
49351,-0.833333333333 1.05847549351,0.6666666666685 -1.5396007178376))", p1 );
boost::geometry::read_wkt( "POLYGON((1.66666666666947 0.192450089732598,0.66
6666666667 0.19245008973,1.16666666667 -0.673575314055,1.6666666666745 -1.539600
7178426,1.66666666666947 0.192450089732598))", p2 );

if( boost::geometry::overlaps( p1, p2 ) ) {
std::cout << "overlaps" << std::endl;
std::deque out;

boost::geometry::intersection( p1, p2, out );

double area = 0.0;

std::cout << "Number of intersection geometries: " << out.size()
<< std::endl;
for( auto& p : out ) {
std::cout << " " << boost::geometry::wkt( p ) << std::endl;
area += boost::geometry::area( p );
}

std::cout << "Intersection area: " << area << std::endl;
} else {
std::cout << "does not overlap" << std::endl;
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.