【问题标题】:Iterate over vertices of CGAL polygon and get int coordinates迭代 CGAL 多边形的顶点并获得 int 坐标
【发布时间】:2018-08-28 14:33:35
【问题描述】:

我的第一个问题是,顶点迭代器和点在 CLION 中是“未知的”。 当我声明一个点并想要访问它的成员函数时,没有自动完成(不像多边形等)。

我的第二个问题是,如何迭代多边形的顶点并将顶点的坐标作为 int 值获取?

思路如下,但是 p.x() 的返回类型不是 int 也不是 double。

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point;
typedef CGAL::Polygon_2<Kernel> Polygon_2;

int main() {
    std::vector<Point> points;

    points.emplace_back(Point(10, 10));
    points.emplace_back(Point(20, 10));
    points.emplace_back(Point(20, 20));
    points.emplace_back(Point(10, 20));

    Polygon_2 poly(points.begin(), points.end());

    for (auto vi = poly.vertices_begin(); vi != poly.vertices_end(); ++vi)
    {
        int x = (*vi).x();
        int y = (*vi).y();
    }

    return 0;
}

编译器错误:

main.cpp:20:13: error: no viable conversion from 'typename cpp11::result_of<typename R::Compute_x_2 (Point_2<Epeck>)>::type' (aka 'Lazy_exact_nt<CGAL::Gmpq>') to 'int'
    int x = (*vi).x();
        ^   ~~~~~~~~~

感谢您的帮助!

【问题讨论】:

    标签: c++ iterator cgal vertex


    【解决方案1】:

    你可以写int x = CGAL::to_double((*vi).x()); 然后你仍然会收到转换警告。你是故意用CGAL::Exact_predicates_exact_constructions_kernel吗?

    【讨论】:

    • 不,我只是从 CGAL 示例中获取的。有更好的选择吗?
    猜你喜欢
    • 2019-12-27
    • 1970-01-01
    • 2011-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多