diff --git a/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Ray_3_do_intersect.h b/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Ray_3_do_intersect.h index bc189388db9..baae9924b8a 100644 --- a/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Ray_3_do_intersect.h +++ b/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Ray_3_do_intersect.h @@ -24,6 +24,7 @@ #include #include +#include // inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf @@ -135,7 +136,7 @@ namespace internal { const Point_3& source = ray.source(); const Point_3& point_on_ray = ray.second_point(); - return bbox_ray_do_intersect_aux( + return do_intersect_bbox_segment_aux( source.x(), source.y(), source.z(), point_on_ray.x(), point_on_ray.y(), point_on_ray.z(), FT(bbox.xmin()), FT(bbox.ymin()), FT(bbox.zmin()), diff --git a/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Segment_3_do_intersect.h b/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Segment_3_do_intersect.h index 1fd921605a3..301cd8a3a84 100644 --- a/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Segment_3_do_intersect.h +++ b/Intersections_3/include/CGAL/internal/Intersections_3/Bbox_3_Segment_3_do_intersect.h @@ -41,7 +41,9 @@ namespace CGAL { namespace internal { - template +template inline bool do_intersect_bbox_segment_aux( @@ -72,15 +74,16 @@ namespace internal { dmin = px - qx; } - if ( tmax < FT(0) ) // test t2 < 0, for a segment or a ray + if ( bounded_0 && tmax < FT(0) ) // test t2 < 0, for a segment or a ray return false; - if ( tmin > dmin ) // test t1 > 1, for a segment + if ( bounded_1 && tmin > dmin ) // test t1 > 1, for a segment return false; // If the query is vertical for x, then check its x-coordinate is in // the x-slab. if( (px == qx) && // <=> (dmin == 0) - ( CGAL::sign(tmin) * CGAL::sign(tmax) ) > 0 ) return false; + ( CGAL::sign(tmin) * CGAL::sign(tmax) ) > 0 ) + return false; // Note: for a segment the condition sign(tmin)*sign(tmax) > 0 has // already been tested by the two previous tests tmax<0 || tmin>dmin // (with dmin==0). @@ -92,14 +95,14 @@ namespace internal { FT dmax = dmin; // set t1=max(t1, 0), for a segment or a ray - if ( tmin < FT(0) ) + if ( bounded_0 && tmin < FT(0) ) { tmin = FT(0); dmin = FT(1); } // set t2=min(t2, 1), for a segment - if ( tmax > dmax ) + if ( bounded_1 && tmax > dmax ) { tmax = FT(1); dmax = FT(1); @@ -148,8 +151,8 @@ namespace internal { { tmin = tmin_; dmin = d_; - if(tmin > dmin) return false; // if t1 > 1, for a segment - if(tmin < FT(0)) { + if(bounded_1 && tmin > dmin) return false; // if t1 > 1, for a segment + if(bounded_0 && tmin < FT(0)) { // set t1=max(t1, 0), for a ray or a segment tmin = FT(0); dmin = FT(1); @@ -162,8 +165,8 @@ namespace internal { { tmax = tmax_; dmax = d_; - if(tmax < FT(0)) return false; // if t2 < 0, for a segment or a ray - if ( tmax > dmax ) + if( bounded_0 && tmax < FT(0)) return false; // if t2 < 0, for a segment or a ray + if( bounded_1 && tmax > dmax ) { // set t2=min(t2, 1), for a segment tmax = FT(1); @@ -207,7 +210,9 @@ namespace internal { if( (dmax*tmin_) > (d_*tmax) ) return false; } - return ( d_ == 0 || tmin_ <= d_ && tmax_ >= FT(0) ); // t1 <= 1 && t2 >= 0 + return ( d_ == 0 || + (!bounded_1 || tmin_ <= d_) && + (!bounded_0 || tmax_ >= FT(0)) ); // t1 <= 1 && t2 >= 0 } template @@ -221,7 +226,7 @@ namespace internal { const Point_3& source = segment.source(); const Point_3& target = segment.target(); - return do_intersect_bbox_segment_aux( + return do_intersect_bbox_segment_aux( source.x(), source.y(), source.z(), target.x(), target.y(), target.z(), FT(bbox.xmin()), FT(bbox.ymin()), FT(bbox.zmin()),