diff --git a/Intersections_3/include/CGAL/Intersections_3/intersection_3_1_impl.h b/Intersections_3/include/CGAL/Intersections_3/intersection_3_1_impl.h index 3eebdc99584..c44eb81f555 100644 --- a/Intersections_3/include/CGAL/Intersections_3/intersection_3_1_impl.h +++ b/Intersections_3/include/CGAL/Intersections_3/intersection_3_1_impl.h @@ -266,17 +266,21 @@ intersection_collinear_segments(const typename K::Segment_3 &s1, if ( cln_order(p,r,q) ){ if ( cln_order(p,s,q) ) return make_object(s2); - if ( cln_order(r,p,s) ) - return r!=p ? make_object( typename K::Segment_3(r,p) ) : make_object(p); - else - return r!=q ? make_object( typename K::Segment_3(r,q) ) : make_object(q); + if ( cln_order(r,p,s) ){ + if (r!=p) return make_object( typename K::Segment_3(r,p) ); + if ( cln_order(r,q,s) ) return make_object(s1); + return make_object(p); + } + return r!=q ? make_object( typename K::Segment_3(r,q) ) : make_object(q); } if ( cln_order(p,s,q) ){ - if ( cln_order(r,p,s) ) - return s!=p ? make_object( typename K::Segment_3(s,p) ) : make_object(p); - else - return s!=q ? make_object( typename K::Segment_3(s,q) ) : make_object(q); + if ( cln_order(r,p,s) ){ + if (s!=p) return make_object( typename K::Segment_3(s,p) ); + if (cln_order(r,q,s)) return make_object(s1); + return make_object(p); + } + return s!=q ? make_object( typename K::Segment_3(s,q) ) : make_object(q); } if ( cln_order(r,p,s) ) diff --git a/Intersections_3/test/Intersections_3/segment_segment.cpp b/Intersections_3/test/Intersections_3/segment_segment.cpp index 4a42c464774..fecf2b873f1 100644 --- a/Intersections_3/test/Intersections_3/segment_segment.cpp +++ b/Intersections_3/test/Intersections_3/segment_segment.cpp @@ -9,6 +9,87 @@ typedef CGAL::Cartesian K; // The construction test has to be working // The equal test has to be working +#define TEST_CASE_SEGMENT_BASE(i,j,k,l,i1,i2) \ +{\ + typename K::Segment_3 s1(pts[i],pts[j]); \ + typename K::Segment_3 s2(pts[k],pts[l]); \ + CGAL::Object obj= CGAL::intersection(s1,s2); \ + typename K::Segment_3 s; \ + typename K::Segment_3 res(pts[i1],pts[i2]);\ + if (!CGAL::assign(s,obj) || ( s!=res && s!=res.opposite() ) ) {\ + std::cerr << "ERROR test-case "<< i << j << k < +void all_cases_collinear(typename K::Point_3 pts[4]){ + std::cout << "4 points cases\n"; + TEST_CASE_EMPTY(0,1,2,3) + TEST_CASE_SEGMENT(0,2,1,3,1,2) + TEST_CASE_SEGMENT(0,3,2,1,1,2) + std::cout << "3 points cases\n"; + TEST_CASE_SEGMENT(0,1,0,2,0,1) + TEST_CASE_SEGMENT(0,2,1,2,1,2) + TEST_CASE_POINT(1,2,0,1,1) + std::cout << "2 points cases\n"; + TEST_CASE_SEGMENT(1,2,1,2,1,2) +} + template void _test_intersection_construct(K) { @@ -68,5 +149,9 @@ int main() { K k; _test_intersection_construct(k); + + + K::Point_3 pts[4] = {K::Point_3(0,0,0),K::Point_3(1,0,0),K::Point_3(2,0,0),K::Point_3(3,0,0)}; + all_cases_collinear(pts); return 0; }