说明
1.学习CGAL中点对象,先对象,多边形对象的构造;
2.学习如何获取相交对象,并打印输出;
重点
相交结果的返回类型为:
CGAL::cpp11::result_of<Kernel::Intersect_2(A, B)>::type, 等价于boost::optional< boost::variant< T… > >
不相交时类型为:boost::optional,相交时(a point or segment)类型为:boost::variant
As explained in the boost manual pages for boost::variant, there are two ways to access the variants. The first examples uses boost::get.
代码
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_2.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point_2;
typedef Kernel::Line_2 Line_2;
typedef Kernel::Segment_2 Segment_2;
typedef Kernel::Intersect_2 Intersect_2;
typedef CGAL::Polygon_2<Kernel> Polygon_2;
#include "print_utils.h"
using namespace std;
int main()
{
Segment_2 seg(Point_2(0, 0), Point_2(2, 2));
Line_2 lin(1, 1, 0);
CGAL::cpp11::result_of<Intersect_2(Segment_2, Line_2)>::type
result = intersection(seg, lin);
if (result)
{
if (const Segment_2* s = boost::get<Segment_2>(&*result))
{
cout << *s << endl;
}
else
{
const Point_2* p = boost::get<Point_2>(&*result);
cout << *p << endl;
}
}
return 0;
}