I'm trying to use the Clipper C++ library to implement an is_bordering
function, as shown below.
bool is_bordering(Path p1, Path p2) {
Paths solutions;
Clipper c;
// execute intersection on paths
c.AddPath(p1, ptSubject, true);
c.AddPath(p2, ptClip, true);
c.Execute(ctIntersection, solutions, pftNonZero);
return (solutions.size() > 0); // the paths share edges
}
int main() {
Path p1, p2;
p1 << IntPoint(0,0) << IntPoint(1,0) << IntPoint(0,1) << IntPoint(0,0);
p2 << IntPoint(1,0) << IntPoint(1,1) << IntPoint(0,1) << IntPoint(1,0);
cout << is_bordering(p1, p2) << endl;
}
I thought that when two bordering polygons were tested with ctIntersection
the result would contain the bordering edges, but for me this returns false. What I expect from the above would be the following, with green representing the solutions
Paths.
How do I get this function working (with the Clipper library)?