diff --git a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_impl.h b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_impl.h index 3e6de96e5c3..d7ce75de19d 100755 --- a/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_impl.h +++ b/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_on_surface_2_impl.h @@ -3801,12 +3801,16 @@ _is_smaller(const DHalfedge* he1, CGAL_precondition(he2->direction() == ARR_RIGHT_TO_LEFT); CGAL_precondition(he1->vertex() != he2->vertex()); - // If he1 points to the bottom left vertex, then it is the smaller. - if ((ps_x1 == ARR_LEFT_BOUNDARY) && (ps_y1 == ARR_BOTTOM_BOUNDARY)) + /* If he1 points to a vertex on the left or the bottom boundary, then it + * is the smaller. + */ + if ((ps_x1 == ARR_LEFT_BOUNDARY) || (ps_y1 == ARR_BOTTOM_BOUNDARY)) return true; - // If he2 points to the bottom left vertex, then it is the smaller. - if ((ps_x2 == ARR_LEFT_BOUNDARY) && (ps_y2 == ARR_BOTTOM_BOUNDARY)) + /* If he2 points to a vertex on the left or the bottom boundary, then it + * is the smaller. + */ + if ((ps_x2 == ARR_LEFT_BOUNDARY) || (ps_y2 == ARR_BOTTOM_BOUNDARY)) return false; return _is_smaller(he1->curve(), he1->vertex()->point(), ps_x1, ps_y1, diff --git a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_unbounded_removal.cpp b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_unbounded_removal.cpp old mode 100755 new mode 100644 index dadb7d20617..76b706319cc --- a/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_unbounded_removal.cpp +++ b/Arrangement_on_surface_2/test/Arrangement_on_surface_2/test_unbounded_removal.cpp @@ -18,10 +18,49 @@ typedef Traits_2::Line_2 Line_2; typedef Traits_2::X_monotone_curve_2 X_monotone_curve_2; typedef CGAL::Arrangement_2 Arrangement_2; typedef Arrangement_2::Vertex_handle Vertex_handle; +typedef Arrangement_2::Face_handle Face_handle; typedef Arrangement_2::Halfedge_handle Halfedge_handle; +bool test(const Arrangement_2& arr) +{ + if (arr.number_of_vertices() != 0) { + std::cerr << "(A) Number of vertices (" << arr.number_of_vertices() + << ") not 0!" << std::endl; + return false; + } + + // Check the validity more thoroughly. + if (! CGAL::is_valid(arr)) { + std::cerr << "The arrangement is NOT valid!" << std::endl; + return false; + } + + return true; +} + +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 curves; curves.push_back(Ray_2(Point_2(0, 0), Point_2(0, 1))); @@ -33,7 +72,6 @@ int main() 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))); - Arrangement_2 arr; std::vector hhs(curves.size()); for (size_t i = 0; i < curves.size(); i++) hhs[i] = insert_non_intersecting_curve(arr, curves[i]); @@ -61,42 +99,63 @@ int main() << ", E = " << arr.number_of_edges() << ", F = " << arr.number_of_faces() << std::endl; - if (arr.number_of_vertices() != 0) { - std::cerr << "(A) Number of vertices (" << arr.number_of_vertices() - << ") not 0!" << std::endl; - return 1; - } + if (!test(arr)) return 1; - // Check the validity more thoroughly. - if (! CGAL::is_valid(arr)) { - std::cerr << "The arrangement is NOT valid!" << std::endl; - 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 - Segment_2 s1(Point_2(0, 0), Point_2(1, 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(s1), arr.unbounded_face()); - Vertex_handle vh = eh1->target(); - Ray_2 ray(Point_2(1, 1), Point_2(2, 2)); - Halfedge_handle eh2 = - arr.insert_from_left_vertex(X_monotone_curve_2(ray), vh); + arr.insert_in_face_interior(X_monotone_curve_2(l1), arr.unbounded_face()); - // Remove the edges - arr.remove_edge(eh2); + if (!test_ray(arr, eh1->face())) return 1; arr.remove_edge(eh1); - if (arr.number_of_vertices() != 0) { - std::cerr << "(B) Number of vertices (" << arr.number_of_vertices() - << ") not 0!" << std::endl; - 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 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 (! CGAL::is_valid(arr)) { - std::cerr << "The arrangement is NOT valid!" << std::endl; - return 1; - } + if (!test_ray(arr, eh2->twin()->face())) return 1; + arr.remove_edge(eh2); - return (0); + return 0; }