我正在尝试使用 Clipper C++ 库来实现一个is_bordering
函数,如下所示。
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;
}
我认为当测试两个边界多边形时ctIntersection
,结果将包含边界边缘,但对我来说这返回错误。我对上面的期望如下,绿色代表solutions
路径。
如何使此功能正常工作(使用 Clipper 库)?