diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h index ff1a7ffb4eb..e4d3818043c 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h @@ -28,12 +28,33 @@ do_intersect(const typename K::Sphere_3& sp, const K& k) { typedef typename K::RT RT; - RT num, den; + typedef typename K::Bounded_side Bounded_side; + + typename K::Bounded_side_3 bounded_side = k.bounded_side_3_object(); + typename K::Compute_squared_radius_3 sq_radius = k.compute_squared_radius_3_object(); + typename K::Construct_center_3 center = k.construct_center_3_object(); + typename K::Construct_source_3 source = k.construct_source_3_object(); + typename K::Construct_target_3 target = k.construct_target_3_object(); + + const Bounded_side source_side = bounded_side(sp, source(seg)); + const Bounded_side target_side = bounded_side(sp, target(seg)); + + if(source_side != target_side) + return true; + else if(source_side == ON_BOUNDED_SIDE) // else if ==> both extremities are on the same side + return false; + else if(source_side == ON_BOUNDARY) + return true; + + CGAL_kernel_assertion(source_side == ON_UNBOUNDED_SIDE && target_side == ON_UNBOUNDED_SIDE); + + // Both out can still be intersecting the sphere + RT num, den; + CGAL::internal::squared_distance_RT(center(sp), seg, num, den, k); - CGAL::internal::squared_distance_RT(sp.center(), seg, num, den, k); return !(compare_quotients(num, den, - Rational_traits().numerator(sp.squared_radius()), - Rational_traits().denominator(sp.squared_radius())) == LARGER); + Rational_traits().numerator(sq_radius(sp)), + Rational_traits().denominator(sq_radius(sp))) == LARGER); } template diff --git a/Intersections_3/test/Intersections_3/test_intersections_Segment_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Segment_3.cpp index 7e56289423e..e8dd7a23868 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Segment_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Segment_3.cpp @@ -68,16 +68,17 @@ public: // see segment_segment.cpp } - // @fixme EPICK void S_Sph() { std::cout << "Segment - Sphere\n"; // No intersection check_do_not_intersect(S(p(4,1,9), p(4,6,-1)), Sph(p(9,2,4), 1)); - check_do_not_intersect(S(p(-2,3,4), p(1,2,-1)), Sph(p(9,2,4), 10000)); + check_do_not_intersect(S(p(-2,3,4), p(1,2,-1)), Sph(p(9,2,4), 10000)); + check_do_intersect(S(p(0,1,0), p(2,1,0)), Sph(p(1,0,0), 1)); check_do_intersect(S(p(-2,3,4), p(1,2,-1)), Sph(p(9,2,4), 100)); + check_do_intersect(S(p(-2,3,4), p(3,2,-5)), Sph(p(9,2,4), 100)); for(int i=0; i