From c21a2da2a1c415f4074a44971eba75689e26be86 Mon Sep 17 00:00:00 2001 From: Andreas Haas Date: Sat, 25 Apr 2015 21:36:57 +0200 Subject: [PATCH] Bugfix in Simple_polygon_visibility_2.h Fixed a bug and added an extra testcase. --- .../CGAL/Simple_polygon_visibility_2.h | 28 ++++++++++++++++--- .../data/test_simple_polygon_22.dat | 19 +++++++++++++ .../test_rotational_visibility.cpp | 12 ++++---- .../Visibility_2/test_simple_visibility.cpp | 8 +++--- .../test_triangular_expansion.cpp | 12 ++++---- 5 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 Visibility_2/test/Visibility_2/data/test_simple_polygon_22.dat diff --git a/Visibility_2/include/CGAL/Simple_polygon_visibility_2.h b/Visibility_2/include/CGAL/Simple_polygon_visibility_2.h index a7de0cdcebb..760aed81256 100644 --- a/Visibility_2/include/CGAL/Simple_polygon_visibility_2.h +++ b/Visibility_2/include/CGAL/Simple_polygon_visibility_2.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -270,13 +271,32 @@ private: output(const Point_2& q, VARR& out_arr) const { std::vector points; - while (!s.empty()) { - points.push_back(s.top()); + while(!s.empty()) { + const Point_2& top = s.top(); + if (top != q) { + points.push_back(top); + } + else if (query_pt_is_vertex) { + points.push_back(top); + } s.pop(); } - Visibility_2::report_while_handling_needles( - traits, q, points, out_arr); + + // Quick fix for now. Can be done faster. + std::vector segments; + + for(typename std::vector::size_type i = 0; + i < points.size() - 1; ++i) + { + segments.push_back(Segment_2(points[i], points[i+1])); + } + + CGAL::insert(out_arr, segments.begin(), segments.end()); + + +// Visibility_2::report_while_handling_needles( +// traits, q, points, out_arr); CGAL_postcondition(out_arr.number_of_isolated_vertices() == 0); CGAL_postcondition(s.empty()); diff --git a/Visibility_2/test/Visibility_2/data/test_simple_polygon_22.dat b/Visibility_2/test/Visibility_2/data/test_simple_polygon_22.dat new file mode 100644 index 00000000000..e75d1320752 --- /dev/null +++ b/Visibility_2/test/Visibility_2/data/test_simple_polygon_22.dat @@ -0,0 +1,19 @@ +0.5 2 +0.5 2 + +0 +6 +0 4 0 0 +0 0 3 2 +3 2 4 0 +4 0 4 4 +4 4 1 2 +1 2 0 4 + +0 +5 +0 4 0 0 +0 0 3 2 +3 2 4 2 +3 2 1 2 +1 2 0 4 diff --git a/Visibility_2/test/Visibility_2/test_rotational_visibility.cpp b/Visibility_2/test/Visibility_2/test_rotational_visibility.cpp index 513950210ee..25b62326126 100644 --- a/Visibility_2/test/Visibility_2/test_rotational_visibility.cpp +++ b/Visibility_2/test/Visibility_2/test_rotational_visibility.cpp @@ -44,14 +44,14 @@ int main() { RSV; CGAL::test_model_methods(); std::cout << "Running test suite with " << GREEN << "Cartesian" << RESET << " Kernel..." << std::endl; - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); } { typedef CGAL::Rotational_sweep_visibility_2 RSV; CGAL::test_model_methods(); std::cout << "Running test suite with " << GREEN << "Cartesian" << RESET << " Kernel..." << std::endl; - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); } }{ typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; @@ -62,14 +62,14 @@ int main() { RSV; CGAL::test_model_methods(); std::cout << "Running test suite with " << GREEN << "EPECK" << RESET << " Kernel..." << std::endl; - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); } { typedef CGAL::Rotational_sweep_visibility_2 RSV; CGAL::test_model_methods(); std::cout << "Running test suite with " << GREEN << "EPECK" << RESET << " Kernel..." << std::endl; - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); } } { @@ -82,11 +82,11 @@ int main() { { typedef CGAL::Rotational_sweep_visibility_2 Visibility_2; CGAL::test_model_methods(); - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); }{ typedef CGAL::Rotational_sweep_visibility_2 Visibility_2; CGAL::test_model_methods(); - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); } } return 0; diff --git a/Visibility_2/test/Visibility_2/test_simple_visibility.cpp b/Visibility_2/test/Visibility_2/test_simple_visibility.cpp index c6b92124fdc..e0de369ede0 100644 --- a/Visibility_2/test/Visibility_2/test_simple_visibility.cpp +++ b/Visibility_2/test/Visibility_2/test_simple_visibility.cpp @@ -47,7 +47,7 @@ int main() { std::cout << GREEN << "Done!" << RESET << std::endl; std::cout << "Running test suite with " << GREEN << "Cartesian" << RESET << " Kernel..." << std::endl; - CGAL::run_tests(21, 0); + CGAL::run_tests(22, 0); } { typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; @@ -60,7 +60,7 @@ int main() { std::cout << GREEN << "Done!" << RESET << std::endl; std::cout << "Running test suite with " << GREEN << "EPECK" << RESET << " Kernel..." << std::endl; - CGAL::run_tests(21, 0); + CGAL::run_tests(22, 0); } { // test Visibility_arrangement_type with extended DCEL @@ -72,11 +72,11 @@ int main() { { typedef CGAL::Simple_polygon_visibility_2 Visibility_2; CGAL::test_model_methods(); - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); }{ typedef CGAL::Simple_polygon_visibility_2 Visibility_2; CGAL::test_model_methods(); - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); } } diff --git a/Visibility_2/test/Visibility_2/test_triangular_expansion.cpp b/Visibility_2/test/Visibility_2/test_triangular_expansion.cpp index 24b604e023a..f277f0bc19e 100644 --- a/Visibility_2/test/Visibility_2/test_triangular_expansion.cpp +++ b/Visibility_2/test/Visibility_2/test_triangular_expansion.cpp @@ -43,13 +43,13 @@ int main() { typedef CGAL::Triangular_expansion_visibility_2 Visibility_2; CGAL::test_model_methods(); - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); } { typedef CGAL::Triangular_expansion_visibility_2 Visibility_2; CGAL::test_model_methods(); - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); } } { @@ -60,12 +60,12 @@ int main() { typedef CGAL::Triangular_expansion_visibility_2 Visibility_2; CGAL::test_model_methods(); - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); }{ typedef CGAL::Triangular_expansion_visibility_2 Visibility_2; CGAL::test_model_methods(); - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); } } @@ -79,11 +79,11 @@ int main() { { typedef CGAL::Triangular_expansion_visibility_2 Visibility_2; CGAL::test_model_methods(); - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); }{ typedef CGAL::Triangular_expansion_visibility_2 Visibility_2; CGAL::test_model_methods(); - CGAL::run_tests(21, 2); + CGAL::run_tests(22, 2); } }