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;
}
bool test_ray(Arrangement_2& arr, Face_handle f)
{
  Segment_2 s1(Point_2(0, 0), Point_2(1, 0));
  Halfedge_handle eh1 =
    arr.insert_in_face_interior(X_monotone_curve_2(s1), f);
  Vertex_handle vh = eh1->target();
  Ray_2 ray(Point_2(1, 0), Point_2(2, 0));
  Halfedge_handle eh2 =
    arr.insert_from_left_vertex(X_monotone_curve_2(ray), vh);

  // Remove the edges
  arr.remove_edge(eh2);
  arr.remove_edge(eh1);

  if (!::test(arr)) return false;

  return true;
}
int main()
{
  Arrangement_2 arr;

  // Construct an arrangement of five linear objects.
  std::vector<X_monotone_curve_2>  curves;
  curves.push_back(Ray_2(Point_2(0, 0), Point_2(0, 1)));
  curves.push_back(Ray_2(Point_2(0, 0), Point_2(1, 0)));
  curves.push_back(Ray_2(Point_2(0, 0), Point_2(0, -1)));
  curves.push_back(Ray_2(Point_2(0, 0), Point_2(-1, 0)));
  curves.push_back(Ray_2(Point_2(0, 0), Point_2(1, 1)));
  curves.push_back(Ray_2(Point_2(0, 0), Point_2(1, -1)));
  curves.push_back(Ray_2(Point_2(0, 0), Point_2(-1, 1)));
  curves.push_back(Ray_2(Point_2(0, 0), Point_2(-1, -1)));

  std::vector<Halfedge_handle> hhs(curves.size());
  for (size_t i = 0; i < curves.size(); i++)
    hhs[i] = insert_non_intersecting_curve(arr, curves[i]);
  bool valid = arr.is_valid();
  std::cout << "Arrangement size:"
            << "   V = " << arr.number_of_vertices()
            << ",  E = " << arr.number_of_edges()
            << ",  F = " << arr.number_of_faces() << std::endl;
  std::cout << "The arrangement is "
            << (valid ? "valid." : "NOT valid!") << std::endl;
  if (! valid) return (1);

  // Remove the edges.
  for (size_t i = 0; i < hhs.size(); i++) {
    arr.remove_edge(hhs[i]);
    bool valid = arr.is_valid();
    std::cout << "  Removed " << i+1 << " curve(s), arrangement is "
              << (valid ? "valid." : "NOT valid!") << std::endl;

    if (! valid) return (1);
  }

  std::cout << "Final arrangement size:"
            << "   V = " << arr.number_of_vertices()
            << ",  E = " << arr.number_of_edges()
            << ",  F = " << arr.number_of_faces() << std::endl;

  if (!::test(arr)) return 1;

  /* Construct another arrangement of a segment connected to a ray.
   * First remove the ray, then remove the segment.
   *
   *  o---------------o
   *  |               |
   *  |               |
   *  |               |
   *  |       o--o----|
   *  |               |
   *  |               |
   *  |               |
   *  o---------------o
   */
  if (!test_ray(arr, arr.unbounded_face())) return 1;

  /* Construct another arrangement of a segment connected to a ray.
   * First remove the ray, then remove the segment.
   *
   *  o---------------o
   *  |               |
   *  |               |
   *  |               |
   *  |       o--o----|
   *  |               |
   *  o---------------o
   *  |               |
   *  o---------------o
   */
  Line_2 l1(Point_2(0, -1), Point_2(1, -1));
  Halfedge_handle eh1 =
    arr.insert_in_face_interior(X_monotone_curve_2(l1), arr.unbounded_face());

  if (!test_ray(arr, eh1->face())) return 1;
  arr.remove_edge(eh1);

  /* Construct another arrangement of a segment connected to a ray.
   * First remove the ray, then remove the segment.
   *
   *  o-----o---------o
   *  |     |         |
   *  |     |         |
   *  |     |         |
   *  |     | o--o----|
   *  |     |         |
   *  |     |         |
   *  |     |         |
   *  o-----o---------o
   */
  Line_2 l2(Point_2(-1, 0), Point_2(-1, 1));
  Halfedge_handle eh2 =
    arr.insert_in_face_interior(X_monotone_curve_2(l2), arr.unbounded_face());

  if (!test_ray(arr, eh2->twin()->face())) return 1;
  arr.remove_edge(eh2);

  return 0;
}
Esempio n. 4
0
int main ()
{
  // Construct the initial arrangement.
  Arrangement_2   arr;
  Segment_2       segs[N_SEGMENTS];
  Halfedge_handle hhs[N_SEGMENTS];
  bool            valid;
  int             k;

  segs[0] = Segment_2 (Point_2 (5, 9), Point_2 (5, 11));
  segs[1] = Segment_2 (Point_2 (5, 9), Point_2 (7, 9));
  segs[2] = Segment_2 (Point_2 (5, 11), Point_2 (7, 9));
  segs[3] = Segment_2 (Point_2 (7, 6), Point_2 (9, 7));
  segs[4] = Segment_2 (Point_2 (9, 7), Point_2 (7, 9));
  segs[5] = Segment_2 (Point_2 (5, 9), Point_2 (7, 6));
  segs[6] = Segment_2 (Point_2 (10, 11), Point_2 (8, 13));
  segs[7] = Segment_2 (Point_2 (8, 13), Point_2 (11, 12));
  segs[8] = Segment_2 (Point_2 (10, 11), Point_2 (11, 12));
  segs[9] = Segment_2 (Point_2 (1, 20), Point_2 (5, 1));
  segs[10] = Segment_2 (Point_2 (5, 1), Point_2 (12, 6));
  segs[11] = Segment_2 (Point_2 (1, 20), Point_2 (12, 6));
  segs[12] = Segment_2 (Point_2 (13, 13), Point_2 (13, 15));
  segs[13] = Segment_2 (Point_2 (13, 15), Point_2 (15, 12));
  segs[14] = Segment_2 (Point_2 (13, 13), Point_2 (15, 12));
  segs[15] = Segment_2 (Point_2 (11, 12), Point_2 (13, 13));
  segs[16] = Segment_2 (Point_2 (1, 20), Point_2 (11, 17));
  segs[17] = Segment_2 (Point_2 (11, 17), Point_2 (20, 13));
  segs[18] = Segment_2 (Point_2 (12, 6), Point_2 (20, 13));
  segs[19] = Segment_2 (Point_2 (15, 12), Point_2 (20, 13));
  segs[20] = Segment_2 (Point_2 (5, 1), Point_2 (20, 1));
  segs[21] = Segment_2 (Point_2 (20, 1), Point_2 (20, 13));
  segs[22] = Segment_2 (Point_2 (15, 5), Point_2 (17, 3));
  segs[23] = Segment_2 (Point_2 (13, 3), Point_2 (17, 3));
  segs[24] = Segment_2 (Point_2 (12, 6), Point_2 (13, 3));
  segs[25] = Segment_2 (Point_2 (17, 3), Point_2 (20, 1));
  
  for (k = 0; k < N_SEGMENTS; k++)
  {
    hhs[k] = insert_non_intersecting_curve (arr, segs[k]);
  }
  valid = arr.is_valid();

  std::cout << "Arrangement size:"
            << "   V = " << arr.number_of_vertices()
            << ",  E = " << arr.number_of_edges() 
            << ",  F = " << arr.number_of_faces() << std::endl;
  std::cout << "The arrangement is "
            << (valid ? "valid." : "NOT valid!") << std::endl;
 
  if (! valid)
    return (1);

  // Remove some edges.
  int  del_indices[N_REMOVE] = {25, 23, 22, 1, 3, 11, 19, 15, 4, 24};

  for (k = 0; k < N_REMOVE; k++)
  {
    arr.remove_edge (hhs[del_indices[k]]);
    valid = arr.is_valid();
    std::cout << "  Removed " << k+1 << " segment(s), arrangement is "
              << (valid ? "valid." : "NOT valid!") << std::endl;

    if (! valid)
      return (1);
  }

  std::cout << "Final arrangement size:"
            << "   V = " << arr.number_of_vertices()
            << ",  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);
}