Fixed removal of unbounded & added corresponding tests

This commit is contained in:
Efi Fogel 2014-05-18 17:16:54 +03:00
parent eb1ac16965
commit a7c7a842f7
2 changed files with 97 additions and 34 deletions

View File

@ -3801,12 +3801,16 @@ _is_smaller(const DHalfedge* he1,
CGAL_precondition(he2->direction() == ARR_RIGHT_TO_LEFT); CGAL_precondition(he2->direction() == ARR_RIGHT_TO_LEFT);
CGAL_precondition(he1->vertex() != he2->vertex()); CGAL_precondition(he1->vertex() != he2->vertex());
// If he1 points to the bottom left vertex, then it is the smaller. /* If he1 points to a vertex on the left or the bottom boundary, then it
if ((ps_x1 == ARR_LEFT_BOUNDARY) && (ps_y1 == ARR_BOTTOM_BOUNDARY)) * is the smaller.
*/
if ((ps_x1 == ARR_LEFT_BOUNDARY) || (ps_y1 == ARR_BOTTOM_BOUNDARY))
return true; return true;
// If he2 points to the bottom left vertex, then it is the smaller. /* If he2 points to a vertex on the left or the bottom boundary, then it
if ((ps_x2 == ARR_LEFT_BOUNDARY) && (ps_y2 == ARR_BOTTOM_BOUNDARY)) * is the smaller.
*/
if ((ps_x2 == ARR_LEFT_BOUNDARY) || (ps_y2 == ARR_BOTTOM_BOUNDARY))
return false; return false;
return _is_smaller(he1->curve(), he1->vertex()->point(), ps_x1, ps_y1, return _is_smaller(he1->curve(), he1->vertex()->point(), ps_x1, ps_y1,

View File

@ -18,10 +18,49 @@ typedef Traits_2::Line_2 Line_2;
typedef Traits_2::X_monotone_curve_2 X_monotone_curve_2; typedef Traits_2::X_monotone_curve_2 X_monotone_curve_2;
typedef CGAL::Arrangement_2<Traits_2> Arrangement_2; 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::Face_handle Face_handle;
typedef Arrangement_2::Halfedge_handle Halfedge_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() int main()
{ {
Arrangement_2 arr;
// Construct an arrangement of five linear objects. // Construct an arrangement of five linear objects.
std::vector<X_monotone_curve_2> curves; 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(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)));
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<Halfedge_handle> hhs(curves.size()); std::vector<Halfedge_handle> hhs(curves.size());
for (size_t i = 0; i < curves.size(); i++) for (size_t i = 0; i < curves.size(); i++)
hhs[i] = insert_non_intersecting_curve(arr, curves[i]); hhs[i] = insert_non_intersecting_curve(arr, curves[i]);
@ -61,42 +99,63 @@ int main()
<< ", E = " << arr.number_of_edges() << ", E = " << arr.number_of_edges()
<< ", F = " << arr.number_of_faces() << std::endl; << ", F = " << arr.number_of_faces() << std::endl;
if (arr.number_of_vertices() != 0) { if (!test(arr)) return 1;
std::cerr << "(A) Number of vertices (" << arr.number_of_vertices()
<< ") not 0!" << std::endl;
return 1;
}
// Check the validity more thoroughly. /* Construct another arrangement of a segment connected to a ray.
if (! CGAL::is_valid(arr)) { * First remove the ray, then remove the segment.
std::cerr << "The arrangement is NOT valid!" << std::endl; *
return 1; * 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 /* Construct another arrangement of a segment connected to a ray.
Segment_2 s1(Point_2(0, 0), Point_2(1, 1)); * 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 = Halfedge_handle eh1 =
arr.insert_in_face_interior(X_monotone_curve_2(s1), arr.unbounded_face()); arr.insert_in_face_interior(X_monotone_curve_2(l1), 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);
// Remove the edges if (!test_ray(arr, eh1->face())) return 1;
arr.remove_edge(eh2);
arr.remove_edge(eh1); arr.remove_edge(eh1);
if (arr.number_of_vertices() != 0) { /* Construct another arrangement of a segment connected to a ray.
std::cerr << "(B) Number of vertices (" << arr.number_of_vertices() * First remove the ray, then remove the segment.
<< ") not 0!" << std::endl; *
return 1; * 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)) { if (!test_ray(arr, eh2->twin()->face())) return 1;
std::cerr << "The arrangement is NOT valid!" << std::endl; arr.remove_edge(eh2);
return 1;
}
return (0); return 0;
} }