From 9ede1f3ee7967652296787ee46fbc507eaf61d90 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Thu, 3 Oct 2019 10:48:52 +0200 Subject: [PATCH] Specialize the cw test to be more robust if the kernel is not exact --- .../Triangle_2_Triangle_2_intersection_impl.h | 50 +++++++++++++------ .../Intersections_2/test_intersections_2.cpp | 6 ++- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/Intersections_2/include/CGAL/Intersections_2/internal/Triangle_2_Triangle_2_intersection_impl.h b/Intersections_2/include/CGAL/Intersections_2/internal/Triangle_2_Triangle_2_intersection_impl.h index 1cf2b107762..7d6b32f3239 100644 --- a/Intersections_2/include/CGAL/Intersections_2/internal/Triangle_2_Triangle_2_intersection_impl.h +++ b/Intersections_2/include/CGAL/Intersections_2/internal/Triangle_2_Triangle_2_intersection_impl.h @@ -30,6 +30,7 @@ #include #include +#include namespace CGAL { @@ -281,13 +282,6 @@ Triangle_2_Triangle_2_pair::vertex(int n) const return cur->point; } -//algorithm taken from here : https://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order -template -bool is_cw(const ArrayOfPoints& ps) -{ - return !CGAL::left_turn(ps[0], ps[1], ps[2]); -} - template typename K::Triangle_2 Triangle_2_Triangle_2_pair::intersection_triangle() const @@ -296,16 +290,18 @@ Triangle_2_Triangle_2_pair::intersection_triangle() const if (!_known) intersection_type(); CGAL_kernel_assertion(_result == TRIANGLE); - std::array res; - res[0]=_pointlist.first->point; - res[1]=_pointlist.first->next->point; - res[2]=_pointlist.first->next->next->point; - if(!is_cw(res)) + if(CGAL::left_turn(_pointlist.first->point, + _pointlist.first->next->point, + _pointlist.first->next->next->point)) { - return Triangle_2(res[0], res[1], res[2]); + return Triangle_2(_pointlist.first->point, + _pointlist.first->next->point, + _pointlist.first->next->next->point); } else { - return Triangle_2(res[0], res[2], res[1]); + return Triangle_2(_pointlist.first->point, + _pointlist.first->next->next->point, + _pointlist.first->next->point); } } @@ -332,6 +328,30 @@ Triangle_2_Triangle_2_pair::intersection_point() const } +//algorithm taken from here : https://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order +template +struct Is_cw{ +bool operator()(const ArrayOfPoints& ps) +{ + typename K::FT res(0); + std::size_t length = ps.size(); + for(std::size_t i = 0; i 0; +} +}; + +template +struct Is_cw{ +bool operator()(const ArrayOfPoints& ps) +{ + return !CGAL::left_turn(ps[0], ps[1], ps[2]); +} +}; + + template typename CGAL::Intersection_traits @@ -358,7 +378,7 @@ intersection(const typename K::Triangle_2 &tr1, for (int i =0; i < ispair.vertex_count(); i++) { points[i] = ispair.vertex(i); } - if(is_cw(points)) + if(Is_cw::Is_exact>()(points)) { std::size_t length = points.size(); diff --git a/Intersections_2/test/Intersections_2/test_intersections_2.cpp b/Intersections_2/test/Intersections_2/test_intersections_2.cpp index aced87d8315..bc1ea6bd322 100644 --- a/Intersections_2/test/Intersections_2/test_intersections_2.cpp +++ b/Intersections_2/test/Intersections_2/test_intersections_2.cpp @@ -98,7 +98,8 @@ struct Test { if (p.size() != q.size()) return false; - if (CGAL::Intersections::internal::is_cw(p)) + if (CGAL::Intersections::internal::Is_cw::Is_exact>()(p)) return false; for(typename Pol::const_iterator itp = p.begin(), itq = q.begin(); itp != p.end(); ++itp, ++itq) if (!approx_equal(*itp, *itq)) @@ -111,7 +112,8 @@ struct Test { std::vector

vec(3); for(int i=0; i<3; ++i){vec[i]=p[i];} - if (CGAL::Intersections::internal::is_cw(vec)) + if (CGAL::Intersections::internal::Is_cw, + typename CGAL::Algebraic_structure_traits::Is_exact>(vec)) return false; return p == q; }