pacify some compiler & cleanup

This commit is contained in:
Efi Fogel 2012-01-26 08:34:35 +00:00
parent 284820786a
commit ac614289df
4 changed files with 96 additions and 110 deletions

View File

@ -19,24 +19,24 @@ typedef CGAL::Arrangement_with_history_2<Traits_2> Arr_with_hist_2;
typedef Arr_with_hist_2::Curve_handle Curve_handle; typedef Arr_with_hist_2::Curve_handle Curve_handle;
typedef CGAL::Arr_simple_point_location<Arr_with_hist_2> Point_location; typedef CGAL::Arr_simple_point_location<Arr_with_hist_2> Point_location;
int main () int main()
{ {
Arr_with_hist_2 arr; Arr_with_hist_2 arr;
// Insert s1, s2 and s3 incrementally: // Insert s1, s2 and s3 incrementally:
Segment_2 s1 (Point_2 (0, 3), Point_2 (4, 3)); Segment_2 s1(Point_2(0, 3), Point_2(4, 3));
Curve_handle c1 = insert (arr, s1); insert(arr, s1);
Segment_2 s2 (Point_2 (3, 2), Point_2 (3, 5)); Segment_2 s2(Point_2(3, 2), Point_2(3, 5));
Curve_handle c2 = insert (arr, s2); insert(arr, s2);
Segment_2 s3 (Point_2 (2, 3), Point_2 (5, 3)); Segment_2 s3(Point_2(2, 3), Point_2(5, 3));
Curve_handle c3 = insert (arr, s3); insert(arr, s3);
// Insert three additional segments aggregately: // Insert three additional segments aggregately:
Segment_2 segs[3]; Segment_2 segs[3];
segs[0] = Segment_2 (Point_2 (2, 6), Point_2 (7, 1)); segs[0] = Segment_2(Point_2(2, 6), Point_2(7, 1));
segs[1] = Segment_2 (Point_2 (0, 0), Point_2 (2, 6)); segs[1] = Segment_2(Point_2(0, 0), Point_2(2, 6));
segs[2] = Segment_2 (Point_2 (3, 4), Point_2 (6, 4)); segs[2] = Segment_2(Point_2(3, 4), Point_2(6, 4));
insert (arr, segs, segs + 3); insert(arr, segs, segs + 3);
// Print out the curves and the number of edges each one induces. // Print out the curves and the number of edges each one induces.
Arr_with_hist_2::Curve_iterator cit; Arr_with_hist_2::Curve_iterator cit;
@ -65,14 +65,14 @@ int main ()
} }
// Perform some point-location queries: // Perform some point-location queries:
Point_location pl (arr); Point_location pl(arr);
Point_2 p1 (4, 6); Point_2 p1(4, 6);
point_location_query (pl, p1); point_location_query(pl, p1);
Point_2 p2 (6, 2); Point_2 p2(6, 2);
point_location_query (pl, p2); point_location_query(pl, p2);
Point_2 p3 (2, 4); Point_2 p3(2, 4);
point_location_query (pl, p3); point_location_query(pl, p3);
return 0; return 0;
} }

View File

@ -16,26 +16,26 @@ typedef CGAL::Arrangement_2<Traits_2> Arrangement_2;
typedef Arrangement_2::Vertex_handle Vertex_handle; typedef Arrangement_2::Vertex_handle Vertex_handle;
typedef Arrangement_2::Halfedge_handle Halfedge_handle; typedef Arrangement_2::Halfedge_handle Halfedge_handle;
int main () int main()
{ {
Arrangement_2 arr; Arrangement_2 arr;
Segment_2 s1 (Point_2 (1, 3), Point_2 (3, 5)); Segment_2 s1(Point_2(1, 3), Point_2(3, 5));
Segment_2 s2 (Point_2 (3, 5), Point_2 (5, 3)); Segment_2 s2(Point_2(3, 5), Point_2(5, 3));
Segment_2 s3 (Point_2 (5, 3), Point_2 (3, 1)); Segment_2 s3(Point_2(5, 3), Point_2(3, 1));
Segment_2 s4 (Point_2 (3, 1), Point_2 (1, 3)); Segment_2 s4(Point_2(3, 1), Point_2(1, 3));
Segment_2 s5 (Point_2 (1, 3), Point_2 (5, 3)); Segment_2 s5(Point_2(1, 3), Point_2(5, 3));
Halfedge_handle e1 = arr.insert_in_face_interior (s1, arr.unbounded_face()); Halfedge_handle e1 = arr.insert_in_face_interior(s1, arr.unbounded_face());
Vertex_handle v1 = e1->source(); Vertex_handle v1 = e1->source();
Vertex_handle v2 = e1->target(); Vertex_handle v2 = e1->target();
Halfedge_handle e2 = arr.insert_from_left_vertex (s2, v2); Halfedge_handle e2 = arr.insert_from_left_vertex(s2, v2);
Vertex_handle v3 = e2->target(); Vertex_handle v3 = e2->target();
Halfedge_handle e3 = arr.insert_from_right_vertex (s3, v3); Halfedge_handle e3 = arr.insert_from_right_vertex(s3, v3);
Vertex_handle v4 = e3->target(); Vertex_handle v4 = e3->target();
Halfedge_handle e4 = arr.insert_at_vertices (s4, v4, v1); arr.insert_at_vertices(s4, v4, v1);
Halfedge_handle e5 = arr.insert_at_vertices (s5, v1, v3); arr.insert_at_vertices(s5, v1, v3);
print_arrangement (arr); print_arrangement(arr);
return 0; return 0;
} }

View File

@ -3,21 +3,13 @@
#include <CGAL/basic.h> #include <CGAL/basic.h>
#ifdef CGAL_USE_GMP #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Gmpz.h>
typedef CGAL::Gmpz Number_type;
#else
#include <CGAL/MP_Float.h>
typedef CGAL::MP_Float Number_type;
#endif
#include <CGAL/Cartesian.h>
#include <CGAL/Arr_segment_traits_2.h> #include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arrangement_2.h> #include <CGAL/Arrangement_2.h>
#include "arr_print.h" #include "arr_print.h"
typedef CGAL::Cartesian<Number_type> Kernel; typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef CGAL::Arr_segment_traits_2<Kernel> Traits_2; typedef CGAL::Arr_segment_traits_2<Kernel> Traits_2;
typedef Traits_2::Point_2 Point_2; typedef Traits_2::Point_2 Point_2;
typedef Traits_2::X_monotone_curve_2 Segment_2; typedef Traits_2::X_monotone_curve_2 Segment_2;
@ -25,59 +17,59 @@ typedef CGAL::Arrangement_2<Traits_2> Arrangement_2;
typedef Arrangement_2::Vertex_handle Vertex_handle; typedef Arrangement_2::Vertex_handle Vertex_handle;
typedef Arrangement_2::Halfedge_handle Halfedge_handle; typedef Arrangement_2::Halfedge_handle Halfedge_handle;
int main () int main()
{ {
// Step (a) - construct a triangular face. // Step(a) - construct a triangular face.
Arrangement_2 arr; Arrangement_2 arr;
Segment_2 s1 (Point_2 (667, 1000), Point_2 (4000, 5000)); Segment_2 s1(Point_2(667, 1000), Point_2(4000, 5000));
Segment_2 s2 (Point_2 (4000, 0), 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)); Segment_2 s3(Point_2(667, 1000), Point_2(4000, 0));
Halfedge_handle e1 = arr.insert_in_face_interior (s1, arr.unbounded_face()); Halfedge_handle e1 = arr.insert_in_face_interior(s1, arr.unbounded_face());
Vertex_handle v1 = e1->source(); Vertex_handle v1 = e1->source();
Vertex_handle v2 = e1->target(); Vertex_handle v2 = e1->target();
Halfedge_handle e2 = arr.insert_from_right_vertex (s2, v2); Halfedge_handle e2 = arr.insert_from_right_vertex(s2, v2);
Vertex_handle v3 = e2->target(); Vertex_handle v3 = e2->target();
Halfedge_handle e3 = arr.insert_at_vertices (s3, v3, v1); arr.insert_at_vertices(s3, v3, v1);
// Step (b) - create additional two faces inside the triangle. // Step (b) - create additional two faces inside the triangle.
Point_2 p1 (4000, 3666), p2 (4000, 1000); Point_2 p1(4000, 3666), p2(4000, 1000);
Segment_2 s4 (Point_2 (4000, 5000), p1); Segment_2 s4(Point_2(4000, 5000), p1);
Segment_2 s5 (p1, p2); Segment_2 s5(p1, p2);
Segment_2 s6 (Point_2 (4000, 0), p2); Segment_2 s6(Point_2(4000, 0), p2);
Halfedge_handle e4 = arr.split_edge(e2, s4, Segment_2 (Point_2(4000, 0), p1)); Halfedge_handle e4 = arr.split_edge(e2, s4, Segment_2(Point_2(4000, 0), p1));
Vertex_handle w1 = e4->target(); Vertex_handle w1 = e4->target();
Halfedge_handle e5 = arr.split_edge (e4->next(), s5, s6); Halfedge_handle e5 = arr.split_edge(e4->next(), s5, s6);
Vertex_handle w2 = e5->target(); Vertex_handle w2 = e5->target();
Halfedge_handle e6 = e5->next(); Halfedge_handle e6 = e5->next();
Segment_2 s7 (p1, Point_2 (3000, 2666)); Segment_2 s7(p1, Point_2(3000, 2666));
Segment_2 s8 (p2, Point_2 (3000, 1333)); Segment_2 s8(p2, Point_2(3000, 1333));
Segment_2 s9 (Point_2 (3000, 2666), Point_2 (2000, 1666)); Segment_2 s9(Point_2(3000, 2666), Point_2(2000, 1666));
Segment_2 s10 (Point_2 (3000, 1333), 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)); Segment_2 s11(Point_2(3000, 1333), Point_2(3000, 2666));
Halfedge_handle e7 = arr.insert_from_right_vertex (s7, w1); Halfedge_handle e7 = arr.insert_from_right_vertex(s7, w1);
Vertex_handle v4 = e7->target(); Vertex_handle v4 = e7->target();
Halfedge_handle e8 = arr.insert_from_right_vertex (s8, w2); Halfedge_handle e8 = arr.insert_from_right_vertex(s8, w2);
Vertex_handle v5 = e8->target(); Vertex_handle v5 = e8->target();
Vertex_handle v6 = arr.insert_in_face_interior (Point_2 (2000, 1666), Vertex_handle v6 =
e8->face()); arr.insert_in_face_interior(Point_2(2000, 1666), e8->face());
arr.insert_at_vertices (s9, v4, v6); arr.insert_at_vertices(s9, v4, v6);
arr.insert_at_vertices (s10, v5, v6); arr.insert_at_vertices(s10, v5, v6);
arr.insert_at_vertices (s11, v4, v5); arr.insert_at_vertices(s11, v4, v5);
// Step (c) - remove and merge faces to form a single hole in the traingle. // Step(c) - remove and merge faces to form a single hole in the traingle.
arr.remove_edge (e7); arr.remove_edge(e7);
arr.remove_edge (e8); arr.remove_edge(e8);
e5 = arr.merge_edge (e5, e6, Segment_2 (e5->source()->point(), e5 = arr.merge_edge(e5, e6, Segment_2(e5->source()->point(),
e6->target()->point())); e6->target()->point()));
e2 = arr.merge_edge (e4, e5, s2); e2 = arr.merge_edge(e4, e5, s2);
print_arrangement (arr); print_arrangement(arr);
return 0; return 0;
} }

View File

@ -2,12 +2,12 @@
// Perform a point-location query and print the result. // Perform a point-location query and print the result.
// //
template <class PointLocation> template <class PointLocation>
void point_location_query void point_location_query(const PointLocation& pl,
(const PointLocation& pl, const typename
const typename PointLocation::Arrangement_2::Point_2& q) PointLocation::Arrangement_2::Point_2& q)
{ {
// Perform the point-location query. // Perform the point-location query.
CGAL::Object obj = pl.locate (q); CGAL::Object obj = pl.locate(q);
// Print the result. // Print the result.
typedef typename PointLocation::Arrangement_2 Arrangement_2; typedef typename PointLocation::Arrangement_2 Arrangement_2;
@ -17,7 +17,7 @@ void point_location_query
typename Arrangement_2::Face_const_handle f; typename Arrangement_2::Face_const_handle f;
std::cout << "The point (" << q << ") is located "; std::cout << "The point (" << q << ") is located ";
if (CGAL::assign (f, obj)) if (CGAL::assign(f, obj))
{ {
// q is located inside a face: // q is located inside a face:
if (f->is_unbounded()) if (f->is_unbounded())
@ -25,12 +25,12 @@ void point_location_query
else else
std::cout << "inside a bounded face." << std::endl; std::cout << "inside a bounded face." << std::endl;
} }
else if (CGAL::assign (e, obj)) else if (CGAL::assign(e, obj))
{ {
// q is located on an edge: // q is located on an edge:
std::cout << "on an edge: " << e->curve() << std::endl; std::cout << "on an edge: " << e->curve() << std::endl;
} }
else if (CGAL::assign (v, obj)) else if (CGAL::assign(v, obj))
{ {
// q is located on a vertex: // q is located on a vertex:
if (v->is_isolated()) if (v->is_isolated())
@ -42,20 +42,18 @@ void point_location_query
{ {
CGAL_error_msg( "Invalid object."); CGAL_error_msg( "Invalid object.");
} }
return;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Perform a vertical ray-shooting query and print the result. // Perform a vertical ray-shooting query and print the result.
// //
template <class VerticalRayShoot> template <class VerticalRayShoot>
void vertical_ray_shooting_query void vertical_ray_shooting_query(const VerticalRayShoot& vrs,
(const VerticalRayShoot& vrs, const typename
const typename VerticalRayShoot::Arrangement_2::Point_2& q) VerticalRayShoot::Arrangement_2::Point_2& q)
{ {
// Perform the point-location query. // Perform the point-location query.
CGAL::Object obj = vrs.ray_shoot_up (q); CGAL::Object obj = vrs.ray_shoot_up(q);
// Print the result. // Print the result.
typedef typename VerticalRayShoot::Arrangement_2 Arrangement_2; typedef typename VerticalRayShoot::Arrangement_2 Arrangement_2;
@ -65,12 +63,12 @@ void vertical_ray_shooting_query
typename Arrangement_2::Face_const_handle f; typename Arrangement_2::Face_const_handle f;
std::cout << "Shooting up from (" << q << ") : "; std::cout << "Shooting up from (" << q << ") : ";
if (CGAL::assign (e, obj)) if (CGAL::assign(e, obj))
{ {
// We hit an edge: // We hit an edge:
std::cout << "hit an edge: " << e->curve() << std::endl; std::cout << "hit an edge: " << e->curve() << std::endl;
} }
else if (CGAL::assign (v, obj)) else if (CGAL::assign(v, obj))
{ {
// We hit a vertex: // We hit a vertex:
if (v->is_isolated()) if (v->is_isolated())
@ -78,10 +76,10 @@ void vertical_ray_shooting_query
else else
std::cout << "hit a vertex: " << v->point() << std::endl; std::cout << "hit a vertex: " << v->point() << std::endl;
} }
else if (CGAL::assign (f, obj)) else if (CGAL::assign(f, obj))
{ {
// We did not hit anything: // We did not hit anything:
CGAL_assertion (f->is_unbounded()); CGAL_assertion(f->is_unbounded());
std::cout << "hit nothing." << std::endl; std::cout << "hit nothing." << std::endl;
} }
@ -89,8 +87,6 @@ void vertical_ray_shooting_query
{ {
CGAL_error_msg( "Invalid object."); CGAL_error_msg( "Invalid object.");
} }
return;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -100,22 +96,20 @@ void vertical_ray_shooting_query
// coordinates. // coordinates.
// //
template <class Arrangement> template <class Arrangement>
void construct_segments_arr (Arrangement& arr) void construct_segments_arr(Arrangement& arr)
{ {
typedef typename Arrangement::Point_2 Point_2; typedef typename Arrangement::Point_2 Point_2;
typedef typename Arrangement::X_monotone_curve_2 Segment_2; typedef typename Arrangement::X_monotone_curve_2 Segment_2;
typedef typename Arrangement::Halfedge_handle Halfedge_handle; typedef typename Arrangement::Halfedge_handle Halfedge_handle;
Point_2 p0 (3,2), p1 (0,3), p2 (2,5), p3 (4,5), p4 (6,3), p5 (3,0); Point_2 p0(3,2), p1(0,3), p2(2,5), p3(4,5), p4(6,3), p5(3,0);
Segment_2 s1 (p1, p2), s2 (p2, p3), s3 (p3, p4), s4 (p4, p5), s5 (p5, p1); Segment_2 s1(p1, p2), s2(p2, p3), s3(p3, p4), s4(p4, p5), s5(p5, p1);
arr.insert_in_face_interior (p0, arr.unbounded_face()); arr.insert_in_face_interior(p0, arr.unbounded_face());
Halfedge_handle e1 = arr.insert_in_face_interior (s1, arr.unbounded_face()); Halfedge_handle e1 = arr.insert_in_face_interior(s1, arr.unbounded_face());
Halfedge_handle e2 = arr.insert_from_left_vertex (s2, e1->target()); Halfedge_handle e2 = arr.insert_from_left_vertex(s2, e1->target());
Halfedge_handle e3 = arr.insert_from_left_vertex (s3, e2->target()); Halfedge_handle e3 = arr.insert_from_left_vertex(s3, e2->target());
Halfedge_handle e4 = arr.insert_from_right_vertex (s4, e3->target()); Halfedge_handle e4 = arr.insert_from_right_vertex(s4, e3->target());
Halfedge_handle e5 = arr.insert_at_vertices (s5, e4->target(), e1->source()); arr.insert_at_vertices(s5, e4->target(), e1->source());
return;
} }