CGAL::2D Arrangements-2

2.3.2 遍历Arrangement Halfedge

Arrangement的一条Halfedge是和一个 X_monotone_curve_2对象绑定,这个curve可以通过e->curve()获取。

e->source()得到源点,e->target()得到目标点,e->twin()得到半边的对边,

第个半边都有一个关联面(incident face),这个关联面在半边的左边,可以通过e->face()获取到。

e->prev()和e->next(),得到关联的上一条和下一条半边。

下面是遍历一个face的halfedge代码段:

cpp 复制代码
template <typename Arrangement>
void print_ccb(typename Arrangement::Ccb_halfedge_const_circulator circ) {
  Ccb_halfedge_const_circulator curr = circ;
  std::cout << "(" << curr->source()->point() << ")";
  do {
    typename Arrangement::Halfedge_const_handle he = curr->handle();
    std::cout << " [" << e->curve() << "] "
              << "(" << e->target()->point() << ")";
  } while (++curr != circ);
  std::cout << std::endl;
}
2.3.3 遍历Arrangement Face

一个Arrangement_2对象arr始终有一个unbounded face,通过arr.unbounded_face()可以拿到,空的Arrangement_2也有一个unbounded face。

通过f->is_unboudned()可以确定一个face是否有边界,有边界的face有一个outer CCB。

下面是遍历face的代码段:

cpp 复制代码
template <typename Arrangement>
void print_face(typename Arrangement::Face_const_handle f) {
  // Print the outer boundary.
  if (f->is_unbounded()) std::cout << "Unbounded face.\n";
  else {
    std::cout << "Outer boundary: ";
    print_ccb(f->outer_ccb());
  }
  // Print the boundary of each of the holes.
  size_t index = 1;
  for (auto hi = f->holes_begin(); hi != f->holes_end(); ++hi) {
    std::cout << " Hole #" << index++ << ": ";
    print_ccb(*hi);
  }
  // Print the isolated vertices.
  index = 1;
  for (auto iv = f->isolated_vertices_begin();
       iv != f->isolated_vertices_end(); ++iv)
  {
    std::cout << " Isolated vertex #" << index++ << ": "
              << "(" << iv->point() << ")\n";
  }
}

遍历整个Arrangement的代码段如下:

cpp 复制代码
void print_arrangement (const Arrangement_2& arr) {
  // Print the arrangement vertices.
  std::cout << arr.number_of_vertices() << " vertices:\n";
  for (auto vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) {
    std::cout << "(" << vit->point() << ")";
    if (vit->is_isolated()) std::cout << " - Isolated.\n";
    else std::cout << " - degree " << vit->degree() << std::endl;
  }
  // Print the arrangement edges.
  std::cout << arr.number_of_edges() << " edges:\n";
  for (auto eit = arr.edges_begin(); eit != arr.edges_end(); ++eit)
    std::cout << "[" << eit->curve() << "]\n";
  // Print the arrangement faces.
  std::cout << arr.number_of_faces() << " faces:\n";
  for (auto fit = arr.faces_begin(); fit != arr.faces_end(); ++fit)
    print_face(fit);
}
2.4修改Arrangement
2.5插入一对不相连的x_Monotone Curves
相关推荐
法哥201243 分钟前
用 C++ 控制 CMW100,到底在干什么?
开发语言·c++
QH139292318801 小时前
NVIDIA H200 H300服务器
运维·服务器·开发语言·网络·信息与通信
OPEN-F1 小时前
Python进阶教程:单元测试与代码质量
开发语言·python·单元测试
阿里嘎多学长1 小时前
2026-08-20 GitHub 热点项目精选
开发语言·程序员·github·代码托管
其实防守也摸鱼1 小时前
Codex破局:前端组件秒级生成的技术文章大纲
开发语言·前端·人工智能·学习·安全·web安全
_Narcissus_2 小时前
枚举和模拟算法笔记
c语言·数据结构·c++·笔记·算法·模拟·枚举
Logintern092 小时前
装饰器和洋葱模式的区分
开发语言·python·架构
冻柠檬飞冰走茶2 小时前
《数据结构实验指导-C++语言版》 在顺序表 list 中查找元素 x
开发语言·数据结构·c++·算法·list
Brilliantwxx2 小时前
【C++】 高阶数据结构图(1)并查集
开发语言·数据结构·c++
lancyu2 小时前
# Agent Loop:AI Agent 的唯一直心骨
开发语言·javascript·人工智能