Esempio n. 1
0
int main()
{
  // Step(a) - construct a triangular face.
  Arrangement_2   arr;

  Segment_2       s1(Point_2(667, 1000), Point_2(4000, 5000));
  Segment_2       s2(Point_2(4000, 0), Point_2(4000, 5000));
  Segment_2       s3(Point_2(667, 1000), Point_2(4000, 0));

  Halfedge_handle e1 = arr.insert_in_face_interior(s1, arr.unbounded_face());
  Vertex_handle   v1 = e1->source();
  Vertex_handle   v2 = e1->target();
  Halfedge_handle e2 = arr.insert_from_right_vertex(s2, v2);
  Vertex_handle   v3 = e2->target();
  arr.insert_at_vertices(s3, v3, v1);

  // Step (b) - create additional two faces inside the triangle.
  Point_2         p1(4000, 3666), p2(4000, 1000);
  Segment_2       s4(Point_2(4000, 5000), p1);
  Segment_2       s5(p1, p2);
  Segment_2       s6(Point_2(4000, 0), p2);

  Halfedge_handle e4 = arr.split_edge(e2, s4, Segment_2(Point_2(4000, 0), p1));
  Vertex_handle   w1 = e4->target();
  Halfedge_handle e5 = arr.split_edge(e4->next(), s5, s6);
  Vertex_handle   w2 = e5->target();
  Halfedge_handle e6 = e5->next();

  Segment_2       s7(p1, Point_2(3000, 2666));
  Segment_2       s8(p2, Point_2(3000, 1333));
  Segment_2       s9(Point_2(3000, 2666), Point_2(2000, 1666));
  Segment_2       s10(Point_2(3000, 1333), Point_2(2000, 1666));
  Segment_2       s11(Point_2(3000, 1333), Point_2(3000, 2666));

  Halfedge_handle e7 = arr.insert_from_right_vertex(s7, w1);
  Vertex_handle   v4 = e7->target();
  Halfedge_handle e8 = arr.insert_from_right_vertex(s8, w2);
  Vertex_handle   v5 = e8->target();
  Vertex_handle   v6 =
    arr.insert_in_face_interior(Point_2(2000, 1666), e8->face());

  arr.insert_at_vertices(s9, v4, v6);
  arr.insert_at_vertices(s10, v5, v6);
  arr.insert_at_vertices(s11, v4, v5);

  // Step(c) - remove and merge faces to form a single hole in the traingle.
  arr.remove_edge(e7);
  arr.remove_edge(e8);

  e5 = arr.merge_edge(e5, e6, Segment_2(e5->source()->point(),
                                        e6->target()->point()));
  e2 = arr.merge_edge(e4, e5, s2);

  print_arrangement(arr);
  return 0;
}
Esempio n. 2
0
int main ()
{
  Arrangement_2   arr;
  Point_2         ps[N_POINTS];
  Vertex_handle   vhs[N_POINTS];
  bool            valid;
  int             k;

  ps[0] = Point_2 (2, 2);
  ps[1] = Point_2 (2, 7);
  ps[2] = Point_2 (4, 9);
  ps[3] = Point_2 (4, 5);
  ps[4] = Point_2 (5, 3);
  ps[5] = Point_2 (7, 1);
  ps[6] = Point_2 (7, 5);
  ps[7] = Point_2 (7, 7);
  ps[8] = Point_2 (9, 3);
  ps[9] = Point_2 (9, 6);

  for (k = 0; k < N_POINTS; k++)
  {
    vhs[k] = insert_point (arr, ps[k]);
  }

  arr.insert_from_left_vertex (Segment_2 (Point_2 (2, 7), Point_2 (4, 7)),
                               vhs[1]);
  TEST_VALIDITY(1);

  arr.insert_from_right_vertex (Segment_2 (Point_2 (6, 6), Point_2 (7, 5)),
                                vhs[6]);
  TEST_VALIDITY(2);

  arr.insert_at_vertices (Segment_2 (Point_2 (7, 1), Point_2 (9, 3)),
                          vhs[5], vhs[8]);
  TEST_VALIDITY(3);

  arr.insert_at_vertices (Segment_2 (Point_2 (7, 5), Point_2 (9, 3)),
                          vhs[6], vhs[8]);
  TEST_VALIDITY(4);

  arr.insert_from_right_vertex (Segment_2 (Point_2 (1, 1), Point_2 (2, 7)),
                                vhs[1]);
  TEST_VALIDITY(5);

  insert_non_intersecting_curve (arr,
                                 Segment_2 (Point_2 (1, 1), Point_2 (7, 1)));
  TEST_VALIDITY(6);

  insert_non_intersecting_curve (arr,
                                 Segment_2 (Point_2 (4, 7), Point_2 (6, 6)));
  TEST_VALIDITY(7);
  
  insert_non_intersecting_curve (arr,
                                 Segment_2 (Point_2 (2, 7), Point_2 (3, 3)));
  TEST_VALIDITY(8);

  insert_non_intersecting_curve (arr,
                                 Segment_2 (Point_2 (3, 3), Point_2 (7, 1)));
  TEST_VALIDITY(9);

  arr.insert_at_vertices (Segment_2 (Point_2 (7, 5), Point_2 (9, 6)),
                          vhs[6], vhs[9]);
  TEST_VALIDITY(10);

  std::cout << "Arrangement size:"
            << "   V = " << arr.number_of_vertices()
            << " (" << arr.number_of_isolated_vertices() << " isolated)"
            << ",  E = " << arr.number_of_edges() 
            << ",  F = " << arr.number_of_faces() << std::endl;
   
  // Check the validity more thoroughly.
  valid = is_valid(arr);
  std::cout << "Arrangement is "
            << (valid ? "valid." : "NOT valid!") << std::endl;

  return (0);
}