From 538e5ca1ee9e1ee942c5915c1d4819244bc711ad Mon Sep 17 00:00:00 2001 From: Francisc Date: Tue, 16 Jul 2013 15:11:04 +0300 Subject: [PATCH] progress with needle test cases --- .../include/CGAL/Simple_visibility_2.h | 80 ++++++++++++------- .../test/include/CGAL/test_simple_polygons.h | 2 + Visibility_2/test/include/CGAL/test_utils.h | 6 +- Visibility_2/test/test_simple_visibility.cpp | 16 ++-- 4 files changed, 64 insertions(+), 40 deletions(-) diff --git a/Visibility_2/include/CGAL/Simple_visibility_2.h b/Visibility_2/include/CGAL/Simple_visibility_2.h index e2a6ae165b0..04767c995b9 100644 --- a/Visibility_2/include/CGAL/Simple_visibility_2.h +++ b/Visibility_2/include/CGAL/Simple_visibility_2.h @@ -95,12 +95,10 @@ public: Output_Arrangement_2 &out_arr ) { - std::vector temp_vertices; - bool query_point_on_source = false; - if (q != he->source()->point()) { if (q != he->target()->point()) { - vertices.push_back(q); + s.push(q); + // vertices.push_back(q); vertices.push_back(he->target()->point()); } else { @@ -108,38 +106,45 @@ public: } } else { - query_point_on_source = true; vertices.push_back(q); vertices.push_back(he->target()->point()); } typename Input_Arrangement_2::Face_const_handle face = he->face(); typename Input_Arrangement_2::Ccb_halfedge_const_circulator circ = face->outer_ccb(); - typename Input_Arrangement_2::Ccb_halfedge_const_circulator curr = circ; - typename Input_Arrangement_2::Halfedge_const_handle he_handle = curr; + typename Input_Arrangement_2::Ccb_halfedge_const_circulator curr; + typename Input_Arrangement_2::Halfedge_const_handle he_handle = circ; while (he_handle != he) { + he_handle = circ; + circ++; + } + + curr = circ; + curr++; + + he_handle = curr; + vertices.push_back(Point_2(he_handle->source()->point())); + + typename Input_Arrangement_2::Ccb_halfedge_const_circulator next; + next = curr; + next++; + + while (curr != circ) { he_handle = curr; + Point_2 curr_vertex = he_handle->target()->point(); + vertices.push_back(curr_vertex); curr++; + next = curr; + next++; } - - do { - he_handle = curr; - Point_2 curr_vertex = he->target()->point(); - temp_vertices.push_back(curr_vertex); - - } while (++curr != circ); - - if (!query_point_on_source) { - vertices.push_back(he->source()->point()); - } - + vertices.push_back(q); std::cout << "Vertices:" << std::endl; for (unsigned int i = 0 ; i < vertices.size() ; i++) { std::cout << vertices[i] << std::endl; } - std::cout << " end" << std::endl; - // visibility_region_impl(q, out_arr); + + visibility_region_impl(q, out_arr); } protected: const Input_Arrangement_2 *p_arr; @@ -161,7 +166,7 @@ protected: return false; } - void visibility_region_impl(Point_2 &q, Output_Arrangement_2 &out_arr) { + void visibility_region_impl(const Point_2 &q, Output_Arrangement_2 &out_arr) { int i = 0; Point_2 w; @@ -181,7 +186,7 @@ protected: w = vertices[1]; s.push(vertices[0]); } - int counter = 0; + do { std::cout << "CASE: " << upcase << std::endl; switch(upcase) { @@ -222,6 +227,7 @@ protected: if ((*vertex_new) != (s_t_prev) && (*vertex_new != s_t)) { std::cout << "switch to scanb" << std::endl; upcase = SCANB; + std::cout << "pushing " << *vertex_new << std::endl; s.push(*vertex_new); } else { // Do not alter stack if it doesn't intersect - push back s_t @@ -237,10 +243,9 @@ protected: s.push(s_t); } } - if (counter == 8) { - // exit(0); + if (i == 9) { +// exit(0); } - counter++; } while(upcase != FINISH); std::cout << "RESULT: " << std::endl; @@ -374,9 +379,11 @@ protected: } else if ((orientation(query_pt, s_j, vertices[i]) == CGAL::RIGHT_TURN) && (orientation(query_pt, s_j_prev, vertices[i]) == CGAL::COLLINEAR)) { - + std::cout << "we're here in collinear" << std::endl; found = true; upcase = LEFT; + std::cout << "right::pushing " << vertices[i] << std::endl; + std::cout << "right::pushing " << vertices[i+1] << std::endl; s.push(vertices[i]); s.push(vertices[i+1]); w = vertices[i+1]; @@ -429,7 +436,11 @@ protected: upcase = LEFT; i = k+1; s.push(intersection_pt); - s.push(vertices[k+1]); + std::cout << "scana::pushing " << intersection_pt << std::endl; + if (intersection_pt != vertices[k+1]) { + std::cout << "scana::pushing " << vertices[k+1] << std::endl; + s.push(vertices[k+1]); + } w = vertices[k+1]; } else { @@ -450,14 +461,17 @@ protected: Segment_2 s2(s_t, vertices[vertices.size()-1]); CGAL::Object result = intersection(s1, s2); if (const Point_2 *ipoint = CGAL::object_cast(&result)) { - intersection_pt = *ipoint; - found = true; - break; + if (*ipoint != s_t) { + intersection_pt = *ipoint; + found = true; + break; + } } k++; } if (found) { if ((intersection_pt == vertices[k+1]) && (intersection_pt == vertices[vertices.size()-1])) { + std::cout << "scanb::done\n"; upcase = FINISH; w = vertices[vertices.size()-1]; s.push(vertices[vertices.size()-1]); @@ -468,6 +482,10 @@ protected: w = intersection_pt; } } + else { + upcase = LEFT; + i++; + } } void scanc(int &i,Point_2 &w, const Point_2 &query_pt) { diff --git a/Visibility_2/test/include/CGAL/test_simple_polygons.h b/Visibility_2/test/include/CGAL/test_simple_polygons.h index ee7a200fd9a..69cb21af4c0 100644 --- a/Visibility_2/test/include/CGAL/test_simple_polygons.h +++ b/Visibility_2/test/include/CGAL/test_simple_polygons.h @@ -70,8 +70,10 @@ bool simple_polygon_halfedge_test_case(std::ifstream &input, std::ifstream &corr Segment_2 curr_seg(hit->source()->point(), hit->target()->point()); if (curr_seg.has_on(query_pt)) { visibility.visibility_region(query_pt, hit, out_arr); + break; } } + std::cout << "exited" << std::endl; return true; // return CGAL::test_are_equal(correct_out_arr, out_arr); } diff --git a/Visibility_2/test/include/CGAL/test_utils.h b/Visibility_2/test/include/CGAL/test_utils.h index 33f151cfdcc..04f1f5951d8 100644 --- a/Visibility_2/test/include/CGAL/test_utils.h +++ b/Visibility_2/test/include/CGAL/test_utils.h @@ -88,13 +88,17 @@ bool test_are_equal(const _Arrangement_2 &arr1, const _Arrangement_2 &arr2) { } eit_fst_mid = eit_fst; eit_snd_mid = eit_snd; + // Now we know where to start the edge comparisons from for (eit_fst, eit_snd ; eit_fst != arr1.edges_end(), eit_snd != arr2.edges_end() ; ++eit_fst, ++eit_snd) { Segment_2 seg_fst = eit_fst->curve(); Segment_2 seg_snd = eit_snd->curve(); - if (seg_fst != seg_snd) { + std::cout << seg_fst << std::endl; + std::cout << seg_snd << std::endl; + if ((seg_fst.source() != seg_snd.source() || seg_fst.target() != seg_snd.target()) && + (seg_fst.source() != seg_snd.target() || seg_fst.target() != seg_snd.source())) { return false; } } diff --git a/Visibility_2/test/test_simple_visibility.cpp b/Visibility_2/test/test_simple_visibility.cpp index 442df1e288a..abffa7591d7 100644 --- a/Visibility_2/test/test_simple_visibility.cpp +++ b/Visibility_2/test/test_simple_visibility.cpp @@ -28,7 +28,7 @@ int main() { typedef CGAL::Arrangement_2 Arrangement_2; // First read arrangement - /* Arrangement_2 arr; + Arrangement_2 arr; std::ifstream input("./data/simple_polygon_test_case_1.in"); CGAL::create_arrangement_from_file(arr, input); CGAL::Visibility_2::Simple_visibility_2 visibility; @@ -39,11 +39,11 @@ int main() { assert(false == (CGAL::test_is_attached >(visibility))); visibility.attach(arr); assert(true == (CGAL::test_are_equal(arr, visibility.arr()))); -*/ + // Run test cases from https://cgal.geometryfactory.com/CGAL/Members/wiki/Visibility/TestCases -/* assert(true == (CGAL::simple_polygon_test_case_1, Arrangement_2> ())); + assert(true == (CGAL::simple_polygon_test_case_1, Arrangement_2> ())); assert(true == (CGAL::simple_polygon_test_case_2, Arrangement_2> ())); - assert(true == (CGAL::simple_polygon_test_case_3, Arrangement_2> ()));*/ + assert(true == (CGAL::simple_polygon_test_case_3, Arrangement_2> ())); assert(true == (CGAL::simple_polygon_test_case_4, Arrangement_2> ())); } { @@ -54,7 +54,7 @@ int main() { typedef CGAL::Arrangement_2 Arrangement_2; // First read arrangement -/* Arrangement_2 arr; + Arrangement_2 arr; std::ifstream input("./data/simple_polygon_test_case_1.in"); CGAL::create_arrangement_from_file(arr, input); CGAL::Visibility_2::Simple_visibility_2 visibility; @@ -65,11 +65,11 @@ int main() { assert(false == (CGAL::test_is_attached >(visibility))); visibility.attach(arr); assert(true == (CGAL::test_are_equal(arr, visibility.arr()))); -*/ + // Run test cases from https://cgal.geometryfactory.com/CGAL/Members/wiki/Visibility/TestCases -/* assert(true == (CGAL::simple_polygon_test_case_1, Arrangement_2> ())); + assert(true == (CGAL::simple_polygon_test_case_1, Arrangement_2> ())); assert(true == (CGAL::simple_polygon_test_case_2, Arrangement_2> ())); - assert(true == (CGAL::simple_polygon_test_case_3, Arrangement_2> ()));*/ + assert(true == (CGAL::simple_polygon_test_case_3, Arrangement_2> ())); } return 0; } \ No newline at end of file