小编h4x*_*x04的帖子

多边形之间的交点作为线剪

我正在尝试使用 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;
}
Run Code Online (Sandbox Code Playgroud)

我认为当测试两个边界多边形时ctIntersection,结果将包含边界边缘,但对我来说这返回 false。我对上面的期望如下,绿色代表solutions路径。

我如何让这个函数工作(使用 Clipper 库)?

geometry clipperlib

5
推荐指数
1
解决办法
315
查看次数

将 Unicode 字符串作为字符循环

使用以下字符串,大小输出不正确。这是为什么,我该如何解决?

string str = " ??????";
cout << str.size();
// outputs 19 rather than 7
Run Code Online (Sandbox Code Playgroud)

我正在尝试str逐个字符地循环,以便我可以将其读入vector<string>大小为 7 的 a,但由于上述代码输出 19,因此我无法执行此操作。

c++ string unicode string-length

2
推荐指数
1
解决办法
1030
查看次数

标签 统计

c++ ×1

clipperlib ×1

geometry ×1

string ×1

string-length ×1

unicode ×1